problems with command in STATA

h1n1

New Member
#1
I'm a beginner in STATA. I need to generate a variable (weinew) that indicates whether or not a subject has a higher than median weight (wei). And then find out the % of higher weight, with 95% CI, in those non-treatment and treatment group (treatm). How to type this command? Thanks!
 

terzi

TS Contributor
#2
Using gen

Hi,

I think this is a common topic that other new STATA users may find useful.

In STATA the command generate is used to create new variables defined as functions of existing ones. By combining it with the if argument you could solve the first part of your problem. Like this

gen newvar=1 if wei>= (Value of median weight)

replace newvar=0 if wei< (Value of median weight)

Replace lets you change the contents of a variable, in this case changing to 0's those cases with weights under the median.

That would create a dichotomous variable named newvar with 1 representing those with weights over the median. With the command proportion you can get the percentages of occurrence with CI.