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
Compare coefficients after reg3This might be something simple, but I cannot wrap my head around it. I am trying to compare coeffici…
How to automate dummy variable adjustment for missing data?I run a fixed effects panel regression on survey data with missing values at my regressors (and DV).…
Hospital beds within distance (geonear)Dear Statalist, I have a dataset with patient IDs and lat/lon data about their residence postal code…
How to test the difference between marginal effects in StataI have an ordinary least squares regression with an interaction term: Code: regress price c.trunk#…
Do file beginner question I am trying to improve my understanding of do file scripting. For disclosure, I program competently…
Subscribe to:
Post Comments (Atom)
0 Response to Syntax for By var: with IF statement
Post a Comment