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
calculate a variable as residual of a regression model, industry-quarter regressionsHi, I want to calculate or generate a new variable called “Doancfq_ram”. I calculate Doancfq_ram as…
Applying condition on variable labelsDear stata users, I am curious whether it is possible to apply IF on variable labels. Or is there an…
Generate timing from existing datesHello everyone, I will appreciate an urgent help with how to go about this statistical issue. I wan…
new variable: replace with nonumeric variable contentHey, I want to generate a new variable out of a variable that is already existing. However, the exi…
Colour Coding Markers In a Weighted Scatter PlotI am trying to create a scatter plot of Disease Mortality (CD_Mortality) and Income (GDP) weighted b…
Subscribe to:
Post Comments (Atom)
0 Response to Saving & using multiple scalars to generate new variables
Post a Comment