Hello,
I am using Stata/BE 17 for Mac and I want to export an Excel file depending on a merge result.
The code below works when merge==1 is observed, but when it is not, of course all observations are deleted and no n=_n is generated, and then command keep if n==1 doesn't work (n ambiguous abbreviation).
Could someone help me, please? I want the code to work even if merge==1 is not observed.
Thank you,
Nicolas
I am using Stata/BE 17 for Mac and I want to export an Excel file depending on a merge result.
The code below works when merge==1 is observed, but when it is not, of course all observations are deleted and no n=_n is generated, and then command keep if n==1 doesn't work (n ambiguous abbreviation).
Code:
keep if _merge==1
bysort id: gen n=_n
keep if n==1
keep id lname fname
if c(N) > 0 {
export excel $orig/questions.xlsx, replace firstrow(var)
}
Thank you,
Nicolas

Comment