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
area specific linear time trend codingthe data is monthly level data. Coding of the time index variables are as follows: Year: 2005-2018…
Univariate Diagnostic Accuracy commandsHello, I am trying to perform a univariate Diagnostic accuracy using 2x 2 values in STATA. As I have…
Problem using bysort, egen, mean(), and weight togetherHello, I am doing my best to follow all the statalist guidelines. My apologies if I am still lackin…
how to back-transform valuesDear Stata users, I have run a mixed model using a natural log-transformed dependent variable (eGFR…
Calcultating Household Diet score(HDDS)I trying to calculate an HDDS score which is basically a sum of food types that a household has cons…
Subscribe to:
Post Comments (Atom)
0 Response to Median, Tercile and Quartile
Post a Comment