+ Reply to Thread
Results 1 to 9 of 9

Thread: [STATA] - Median calculation

  1. #1

    [STATA] - Median calculation



    Hi,

    I have 100 subjects with 6 visits over a period of 6 month and their weight recorded at each visit. how can I calculate mean and SD of each subject's weight (all 6 visits),for all 100 subjects. Any help is appreciated.

    Also,

    I have 100 subjects with 6 visits over a period of 6 months. some may have less then 6 visits. how can i calculate the total subjects with more than or equal to 2 visits and also the median.
    Last edited by Dragan; 09-17-2010 at 09:09 AM. Reason: Merged

  2. #2
    RotParaTon
    Points: 46,159, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,066
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: Median calculation

    Can you explain what about this is giving you difficulties? Also if you use a certain stats software you should let us know which one so we could tailor our responses to you in that regard.

  3. #3
    Points: 1,598, Level: 22
    Level completed: 98%, Points required for next Level: 2

    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Median calculation

    i am using STATA and i am new to it. I am able to calculate median and SD for 'all the patients in a visit' but I am not sure how to do it for individual patient accross visits (row median and SD).
    Say for ex:
    id visit 1 visit 2 visit 3 visit 4 Median SD
    1 100 99 120 200 ? ?
    2 110 109 017 100 ? ?
    3 90 87 99 92 ? ?
    4 88 90 92 91
    5 70 66 68 67
    ------------------------------

    Thank you,
    Gopi.

  4. #4
    RotParaTon
    Points: 46,159, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,066
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: Median calculation

    Alright. Sounds more like a STATA specific question which means I am of no use to you. But I'll send it over to the other software sub-board so it gets more attention where it's deserved.

  5. #5
    Points: 1,598, Level: 22
    Level completed: 98%, Points required for next Level: 2

    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: [STATA] - Median calculation

    Thank you. Where should I check for the response, could you please let me know.

  6. #6
    RotParaTon
    Points: 46,159, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,066
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: [STATA] - Median calculation

    Well in the other software sub board is where the thread will be located but I left a redirect where you originally posted that will stay there for a week. But if you click the redirect it actually takes you to the thread in the other software board so you don't need to worry.

  7. #7
    Points: 2,352, Level: 29
    Level completed: 35%, Points required for next Level: 98

    Location
    Paris
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Median calculation

    Quote Originally Posted by gopilth@yahoo.com View Post
    i am using STATA and i am new to it. I am able to calculate median and SD for 'all the patients in a visit' but I am not sure how to do it for individual patient accross visits (row median and SD).
    Say for ex:
    id visit 1 visit 2 visit 3 visit 4 Median SD
    1 100 99 120 200 ? ?
    2 110 109 017 100 ? ?
    3 90 87 99 92 ? ?
    4 88 90 92 91
    5 70 66 68 67
    ------------------------------

    Thank you,
    Gopi.
    Hi there,

    Is this what your dataset looks like? You have variables "visit1" "visit2" etc. organized like this in your table?

    Other question: for those in your sample with less than 6 visits, do you have records only for visits 1 and 2 or do you have records for non-consecutive visits?

    Etienne

  8. #8
    Points: 1,598, Level: 22
    Level completed: 98%, Points required for next Level: 2

    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: [STATA] - Median calculation

    1. yes, my data looks like the way I described- visit 1, visit 2 ...visit 6.
    2. I have data on all the 6 visits for most of the subjects but some have less then 6 visits, may or may not be consecutive. for ex subject 1 might have attended visit1 and visit 6 but missed all other visits, subject 2 might have attended only visit1 and missed the rest and so on. hope this helps. Thanks a lot for your help.

  9. #9
    Points: 2,352, Level: 29
    Level completed: 35%, Points required for next Level: 98

    Location
    Paris
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: [STATA] - Median calculation


    My suggestion is:

    1/ for each subject generate a variable for the number of visits for this particular subject. For instance:

    gen n = (visit1<.)+(visit2<.)+(visit3<.)+(visit4<.)+(visit5<.)+(visit6<.)

    2/ then calculate the mean as follows (you don't want to do smtg like "gen mean = (visit1+visit2+visit3+visit4+visit5+visit6)/6 because you will end with missing values for all individuals with less than 6 visits):

    gen mean = 0
    forv k = 1/6 {
    replace mean = mean + visit`k'/n if visit`k' < .
    }

    Hope this helps! In particular I think that this helps constructing other statistics such as standard deviations if you want to.
    Last edited by Etienne; 09-19-2010 at 03:42 AM.

+ Reply to Thread

Similar Threads

  1. Replies: 4
    Last Post: 01-05-2011, 11:03 PM
  2. stata - incidence calculation
    By robo_2 in forum Stata
    Replies: 2
    Last Post: 02-12-2010, 09:46 AM
  3. Replies: 0
    Last Post: 05-12-2009, 10:44 AM
  4. mean, median
    By shezza76 in forum Statistics
    Replies: 3
    Last Post: 10-23-2008, 10:36 PM
  5. Replies: 1
    Last Post: 10-05-2006, 05:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats