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
How to Append Logistic Regression Outputs Using ASDOCHi, Stata Users: Can someone please demonstrate how to append logistic regression outputs using the…
volatility of the firm's equity(annualized standard deviation)Dear All, Hope my msg finds you very well. I have a panel data 252 observations (daily ) (id, date…
Distance between two coordinatesGoodmorning, I want to calculate the distance between two x,y coordinates. However, I have a list of…
Interaction Using Single Hashtag (#)Dear Experts, My objective is to get two coefficients with corresponding p-values before and after …
Creating time trendsHi, I have a question regarding creating time trends to account for time effects before and after t…
Subscribe to:
Post Comments (Atom)
0 Response to Saving & using multiple scalars to generate new variables
Post a Comment