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
syntax of forecast errorHi all, I am currently working on a state-dependent fiscal multiplier using forecast error to ident…
Splitting a string variable into observations (instead of variables)Hi everyone I have two datasets. The master data include, among others, a list of (numeric) zip cod…
table with coefficients from regressionsHello With the following code I am able to run the regressions and get the constant and the t-stati…
Program to label variables from list of words - How to use fewer single and double quotesI am used to make reusable programs, and find myself having issues with how I use the local single q…
Questions about components' stationarity in VAR model.I am very confused about the stationarity of variables in VAR. It seems that different econometrics …
Subscribe to:
Post Comments (Atom)
0 Response to Syntax for By var: with IF statement
Post a Comment