This is not a pressing matter as I easily found a work-around, I was just curious if anyone could tell me how to fix a syntax error I encountered. I was collapsing a dataset so that we kept only one observation per one variable and we needed the kept observation to be the one with the fewest missing values. I generated a variable that was the count of the non missing variables called "MissCount" and then tried to run this code:
by IDvar: gen KeepObs = 1 if MissCount == max(MissCount)
keep if KeepObs == 1
I also tried this with egen, neither worked.
I worked around this easily with:
by IDvar: egen KeepObs = max(MissCount)
keep if KeepObs == MissCount
But I was curious if someone could explain why my first attempt doesn't work? Again, not a pressing matter, but thank you!
Related Posts with Syntax for By var: with IF statement
Quantile regressionHello, I'm doing a thesis on the basis of RAND HIE data. I would like to run a quantile regression w…
Esttab produces wrong resultsHello, I conducted logit regressions using eststo for three different countries and then put the re…
missed ANOVA Matrix in OLS regressionArray Hi, it is my results for Ols regression and doesn't have ANOVA matrix but my tutor results sho…
ommited control variableHello, I have a sample of 158 firms. I control for industry, and I have 26 industry dummies. One of…
Two errors - don't understand whyCan anyone advise? Code: . use "Z:\Data\jt\survival.dta" . capture erase "Z:\Data\jt\file.dta" . …
Subscribe to:
Post Comments (Atom)
0 Response to Syntax for By var: with IF statement
Post a Comment