Philippe Van Kerm and I have noticed an issue with -egen- resetting the number of observations after a specific type of error (not providing an argument). Any ideas about what is happening? Is this is a bug? Windows/MP18.5 (updated to 2024-12-18). Examples below (with some counter-examples as part of detective work)
Code:
. cscript
-------------------------------------------------------------------------BEGIN
. set obs 1000
Number of observations (_N) was 0, now 1,000.
. di _N // 1000 obs
1000
. * specific mistake with egen (non-existent egen function - same as misspelt; and no argument
. cap noisily egen dd = something_that_leads_to_egen_error()
unknown egen function something_that_leads_to_egen_error()
. di _N // observations are now down to zero!
0
.
. cscript
-------------------------------------------------------------------------BEGIN
. set obs 1000
Number of observations (_N) was 0, now 1,000.
. di _N // 1000 obs
1000
. cap noisily egen dd = mean() // no argument
invalid syntax
. di _N // observations are now down to zero!
0
.
. cscript
-------------------------------------------------------------------------BEGIN
. set obs 1000
Number of observations (_N) was 0, now 1,000.
. di _N // 1000 obs
1000
. ge x = _N
. su x
Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
x | 1,000 1000 0 1000 1000
. cap noisily egen dd = maen(x) // misspelt egen function but with an argument
unknown egen function maen()
. di _N // observations are NOT now down to zero!
1000
.
. cscript
-------------------------------------------------------------------------BEGIN
. set obs 1000
Number of observations (_N) was 0, now 1,000.
. di _N // 1000 obs
1000
. cap noisily egen dd = maen() // misspelt egen function & no argument)
unknown egen function maen()
. di _N // observations are now down to zero!
0

Comment