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
Coefplot for balance tests using rdrobustI'm trying to plot the coefficients of rdrobust estimates using coefplot: Here is what I'm trying to…
Making inference on marginal effect or coefficient estimates in ProbitDo we make inferences on marginal effects or coefficient estimates in a Probit model? I am asking be…
Drop row where value is lower than another for a specific columnHi all, I am looking to clean a data set I have. I think what I want to achieve should only take a f…
Generating variables recording the properties of other variablesHi all, I'm a beginner of Stata user. I'm struggling with my dataset. I have four variables: househo…
Titles for graphs in loopsHello everyone, I'm trying to save some graphs, and the code is working for saving them, but I can'…
Subscribe to:
Post Comments (Atom)
0 Response to Saving & using multiple scalars to generate new variables
Post a Comment