Hi all,
I am trying to create a new indicator variable based on whether an individual is in the top 5th percentile across age. Here is what I have so far - struggles to create new variable based on the minimum value stored a local 95th percentile.
Many thanks in advance for any help on this.
Kind regards,
Michelle
local VARS height age bmi
local RACE2 white black other
foreach var of local VARS {
foreach race2 of local RACE2 {
summarize `var' if race2 == "`race2'", d
local p95 `r(p95)'
dis "for variable `var' & race2 == `race2'; p95 = `r(p95)', mean (SD) = `r(mean)' (`r(sd)')
}
foreach var of local VARS
gen `var'_group = 1 if `var' >= `p95' & `var' < .
replace `var'_group = 0 if `var' < `p95'
}
}
Related Posts with Saving & using multiple scalars to generate new variables
Bug in margins with factor variable notation for quadratic termDescription: I think I found a bug with margins. specifically with the atmeans option. If the model…
Correct use of constraint in foreach cycleHi, I would like to set constraints later use them in a program. Here is a small example: sysuse au…
not enough memory for "merge"Dear community! I am trying two merge two files based on a facilityID which, however, is a unique i…
forval loop with a time range and a large dataset: can it faster?Dear Stata users, I am using Stata 15.0 I have a variable "Dyadic_Tie", and it should be counted h…
How to save the predicted value of regressionsDear Statalists' Can any one help me how to save the predicted value of many regressions. I have to …
Subscribe to:
Post Comments (Atom)
0 Response to Saving & using multiple scalars to generate new variables
Post a Comment