Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error using xtreg - r(2000) "No observations"

    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 country[_n] != country[_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 country[_n] != country[_n-1]
    
    xtset ppp_increment year, yearly
    
    xtreg ppp_increment realxrate l1.realxrate [etc.]

    Thanks in advance for any help!
    Martin
    Last edited by Martin Valuet; 12 Aug 2020, 06:05.

  • #2
    Why are you setting the panel variable as purchasing parity index
    Code:
    xtset ppp year, yearly
    Each ppp is unique so the lagged variables result in missing:
    Code:
    . sort ppp year
    
    . format ppp %20.15f
    
    . l in 1/5, sepby(ppp)
    
         +----------------------------------------------------------------------------------------------------------+
         | country   year      xrate                 ppp    id   capt   realxr~e    lnrxrate   oecd   g7   ppp_in~t |
         |----------------------------------------------------------------------------------------------------------|
      1. |     BRA   1970   1.67e-12   0.000000000001544    25     34          1           0      0    0          0 |
         |----------------------------------------------------------------------------------------------------------|
      2. |     ZAR   1970   1.67e-12   0.000000000001679   186     34          1           0      0    0          0 |
         |----------------------------------------------------------------------------------------------------------|
      3. |     BRA   1971   1.92e-12   0.000000000001790    25     34   .9314009   -.0710655      0    0          0 |
         |----------------------------------------------------------------------------------------------------------|
      4. |     ZAR   1971   1.67e-12   0.000000000001845   186     34   1.104533     .099423      0    0          0 |
         |----------------------------------------------------------------------------------------------------------|
      5. |     ZAR   1972   1.67e-12   0.000000000001940   186     34   1.161504    .1497157      0    0          0 |
         +----------------------------------------------------------------------------------------------------------+
    Try:
    Code:
    xtset id year
    Also, this line makes every value 0 since it is always true:
    Code:
    replace ppp_increment = 0 if year[_n] != year[_n-1]
    I think you want something like:
    Code:
    xtset id year
    xtreg d.ppp L(0/29).real


    Comment


    • #3
      Hello Scott,

      thanks for these indications. The shortened syntax for the lags is much appreciated.

      The
      Code:
      replace ppp_increment = 0 if year[_n] != year[_n-1]
      was a left-over from my actual code - I later corrected my message to replace this line with the "country" variable from the example dataset.

      My panel variable was indeed absurd, thank you very much for pointing it out!

      Now it works.

      Comment

      Working...
      X