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
Create multiple observations from a current one considering a specific variableI have a set of companies with the date they were founded and the date they were acquired by other c…
Picking initial log of value added per worker per country in their initial yearHi, I am trying to figure it out how to set up Stata to pick the first log of real value added per …
difference in results between including an interaction with categorical variable v. subgroup analysis Hi all! I’m running multinomial logit models with gender as an outcome. Goal: look at gender over t…
Is there any way we could permanently set the graphregion(fcolor(white))?I like white plotting background. So, to make it white, I have to set the graph region color option …
GamHello I am not able to get GAM to work anyone has advice on how to download GAM? Thank you …
Subscribe to:
Post Comments (Atom)
0 Response to Syntax for By var: with IF statement
Post a Comment