[STATA] - Median calculation

#1
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 a moderator:

Dason

Ambassador to the humans
#2
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
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.
 

Dason

Ambassador to the humans
#4
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.
 

Dason

Ambassador to the humans
#6
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
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.
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
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
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: