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
Master thesis - multiple excel sheets and make a dataset to be one variableHi! Im doing my master thesis and im not that good at STATA so I really need some help to begin! I …
How to make a loop continue working if a variable it is not found?Hello. I am trying to generate graphs from some variables. I do not have all possible combinations …
Filling in Missing YearsHi Statalist, I'm trying to fill in missing years for my dataset, but something is off. The origina…
STATA can't handle TOEPLITZ 1 (MDEPENDENT(1)) and AR(1) when bootstrapping mixed modelsTOEPLITZ 1 (MDEPENDENT(1)) bootstrap, reps(20) seed(1) saving(mdep1test): mixed Pain i.RANDOM W W2 …
Looping through two different sets of valuesI have data from several years. Each is stored in a file entitled "year 1" "year 2" .... "year 8". T…
Subscribe to:
Post Comments (Atom)
0 Response to Syntax for By var: with IF statement
Post a Comment