Hi, I want to create dummy variables based on the median. Sometiems I do that based on quartile and tercile. I do the following
1. This will create a yearly median variable and median dummy
egen ana= xtile(num), n(2) by(fyear)
gen num_dummy = cond(missing(ana), ., (ana>1))
2. This will create a yearly tercile variable and a dummy based on top tercile
egen ana= xtile(num), n(3) by(fyear)
gen num_dummy = cond(missing(ana), ., (ana>2))
3. This will create a yearly quartile variable and a dummy based on top quartile
egen ana= xtile(num), n(4) by(fyear)
gen num_dummy = cond(missing(ana), ., (ana>3))
Though I checked that the codes give me the correct answer even if I calculate them by using slightly different code, I want to make sure from the expert that I am doing it correctly.
So, experts, could you please tell me whether I am doing things correctly or not?
Related Posts with Median, Tercile and Quartile
Problem generating a new variable because of missing valuesHi everyone! I'm fairly new to Stata & Statalist, so I apologize in advance if this question has…
Correlations between consecutive observationsHi, Suppose I have the following dataset id year measure1 measure2 1 2000 0.41 - 1 2001 0.19 0.50…
VECM with GARCH errorsHi Do anyone knows how to perform e VECM model with GARCH errors with STATA? …
Loop commandI need to estimate an ARMA model order from (0,0) to (5,5). How would you go about writing an loop c…
ICC and VPC using mepoisson commandHi everybody: I am using the command "mepoisson" in Stata 15 and I have doubt how I can calculate t…
Subscribe to:
Post Comments (Atom)
0 Response to Median, Tercile and Quartile
Post a Comment