Hello,

I am trying to perform a lagged regression on a panel dataset, using xtreg. I get the error "r(2000) - No Observations".
Looking at different posts on this topic, I could already rule out the most frequently mentioned causes. All my variables are numeric, and my dataset does not have any missing value over the 32k observations.

I replicated the relevant part of my code using an online dataset from the Stata website. Like in my dataset, all relevant variables are numeric and there are no gaps. I get the same error.

This is the code:

Code:
webuse pennxrate.dta, clear

sort country year
gen ppp_increment = ppp - ppp[_n-1]
replace ppp_increment = 0 if year[_n] != year[_n-1]

xtset ppp year, yearly
    
xtreg ppp_increment realxrate l1.realxrate l2.realxrate l3.realxrate l4.realxrate ///
l5.realxrate l6.realxrate l7.realxrate l8.realxrate l9.realxrate l10.realxrate l11.realxrate ///
l12.realxrate l13.realxrate l14.realxrate l15.realxrate l16.realxrate l17.realxrate l18.realxrate ///
l19.realxrate l20.realxrate l21.realxrate l22.realxrate l23.realxrate l24.realxrate l25.realxrate ///
l26.realxrate l27.realxrate l28.realxrate l29.realxrate
My model requires me to regress over 30 periods, but the issue appears as soon as I add the first lag.

What is my mistake here?

Another question, more out of curiosity:
I also tried using the my dependent variable as panel variable with xtset. In that case the error output is the following. "r(198) - the panel variable price_increment may not be included as an independent variable". I am confused: Why does Stata interpret the variable as independent, even though it is the first to be mentioned after the "xtreg" command?
Using the example dataset from Stata, the code would look like this (unlike the example dataset, mine does not have repeated time values).

Code:
gen ppp_increment = ppp - ppp[_n-1]
replace ppp_increment = 0 if year[_n] != year[_n-1]

xtset ppp_increment year, yearly

xtreg ppp_increment realxrate l1.realxrate [etc.]

Thanks in advance for any help!
Martin