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
ARDL ECM bounds testHi, I have selected optimal lags for an ARDL with two variables, plus impulse dummies (time series)…
Latent Class Model on a Mixture-Amount Discrete Choice ExperimentHello I performed a discrete choice experiment which included 8 mixtures terms (the proportions of …
Estimating incidence rates from Poisson and marginsHi Stata users I've asked beforre, but realize that my post may have been unclear, so hopefully I c…
generating new variableHello members, Please i want to generate a new variable "marital status" to have categories "1. Mari…
Summary table (specifically standard deviation) for ANOVA commandI am trying to get a summary table for my anova command (like the subcommand tabulate does when you …
Subscribe to:
Post Comments (Atom)
0 Response to Saving & using multiple scalars to generate new variables
Post a Comment