Announcement

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

  • r2000 error

    Hello

    I'm currently studying towards a masters degree in Economics and am fairly new to stata
    I signed up to this forum purely because I'm having problems with this error.

    I'm running a panel data regression using lags of both explanatory and dependent variables and comparing various estimators results (Difference GMM, System GMM etc...)

    I'm getting this no observations error but I can't understand why,

    I've set both cross-sectional and time series values... why does it say I have no observations?

    Would love some help

    Thank you in advance

    Attached is my program for convenience

    Sincerely,
    Matthew Williamson
    Attached Files

  • #2
    Welcome to the Stata Forum / Statalist.

    Your query remained unanswered so far, and I guess it could have been given a reply, had you followed the FAQ advice on how to share data, and the recommendation to present commands in Stata.

    That said, hazarding a guess, you may start by checking whether there is a string variable. If so, make sure to turn it into numeric.

    Otherwise, it may be something related to the way the time series operators were created.

    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      Welcome to Statalist, Matthew.

      Following up on Marco's excellent advice, that the problem is most likely in your data, since you are generating your data in a simulation, at the point where your code fails, you should find the most recent data in memory. At that point, explore your data, perhaps saving it to a file in case the answer isn't immediately obvious, try running the command that failed by hand, and so forth. Basic debugging, in other words. Start with one set of simulated data, get your estimation commands working on it, then build up the simulation structure and looping around that. Always start with working code and add complexity a step at a time.

      You may find useful guidance in the Stata Programming Reference Manual PDF included with your installation.

      In brief, this is not the sort of problem that yields to introspection as easily as it does to inspection.

      Comment


      • #4
        Back at the computer, I assembled the following from your two do-files.
        Code:
        drop _all
        clear
        set more off
        set seed 10
        // The local commands below set all the parameters for the experiments.
        local beffect = 0 // This variable controls the degree of correlation between
                          // between x and the fixed effect.  When beffect = 0, there
                          // is no omitted variable bias.  As beffect increases,
                          // omitted variable bias increases.
        local numN = 50 // This sets the number of cross-sectional units
        local numT = 20 // This sets the number of time observations per unit
        local numNT = `numN'*`numT' // This sets the total number of observations
        local beta0 = 1 // This sets the intercept term
        local betax = 1 // This sets the slope coefficient for x
        local betax2 = 1
        local betax3 = 0.5
        local reps = 1
        
        local i 1
        local betay 0.1
        
        // CODE FROM DPDprog in ProjectA.do
        set obs `numN'
        gen id = _n
        // "ai" is the part of the error term that doesn't change over time for a given
        // unit.
        gen ai = rnormal()
        expand `numT'
        bysort id: gen t=_n
        xtset id t
        gen x = (`beffect'*ai + rnormal())/sqrt(1+`beffect'^2)
        // "uit" is the part of the error term that varies across time
        gen uit = rnormal()
        // The total error term is the sum of "a" and "e"
        gen error = ai + uit
        gen y = `beta0' + `betax'*x + error
        replace y = `beta0' + `betax'*x +`betax2'*L.x + `betax3'*L2.x + `betay'*L.y + error if t > 1 
        list if id==1
        Code:
        . replace y = `beta0' + `betax'*x +`betax2'*L.x + `betax3'*L2.x + `betay'*L.y + error if t > 1
        (950 real changes made, 950 to missing)
        
        . list if id==1
        
              +---------------------------------------------------------------------+
              | id          ai    t           x         uit       error           y |
              |---------------------------------------------------------------------|
           1. |  1   -.9078662    1   -.8434497   -1.189236   -2.097102   -1.940552 |
           2. |  1   -.9078662    2    .6660743   -1.278092   -2.185958           . |
           3. |  1   -.9078662    3   -.4574957   -.7420049   -1.649871           . |
           4. |  1   -.9078662    4   -.2380227    .0919268   -.8159394           . |
           5. |  1   -.9078662    5   -1.644524   -.1542336     -1.0621           . |
              |---------------------------------------------------------------------|
           6. |  1   -.9078662    6     1.94938    .4811275   -.4267386           . |
           7. |  1   -.9078662    7    -1.00339   -.5298639    -1.43773           . |
           8. |  1   -.9078662    8    .2726943   -1.148116   -2.055982           . |
           9. |  1   -.9078662    9    .1362388    .4592514   -.4486148           . |
          10. |  1   -.9078662   10    .2425972   -.2906497   -1.198516           . |
              |---------------------------------------------------------------------|
          11. |  1   -.9078662   11    1.165814    -1.29181   -2.199676           . |
          12. |  1   -.9078662   12   -.1931612   -.0336692   -.9415354           . |
          13. |  1   -.9078662   13    .5661978   -.6400746   -1.547941           . |
          14. |  1   -.9078662   14    .0136136   -2.141149   -3.049016           . |
          15. |  1   -.9078662   15   -1.217014    -.499754    -1.40762           . |
              |---------------------------------------------------------------------|
          16. |  1   -.9078662   16    .7375849    1.328072     .420206           . |
          17. |  1   -.9078662   17     .506507     2.29134    1.383474           . |
          18. |  1   -.9078662   18    2.113863    .8997558   -.0081104           . |
          19. |  1   -.9078662   19    1.167357   -.2680276   -1.175894           . |
          20. |  1   -.9078662   20    -.043169   -1.235314    -2.14318           . |
              +---------------------------------------------------------------------+
        The list command makes the source of your error message clear: most of your values of y are missing. The message from the replace command makes it clear where the problem originated: you replaced 950 values of y with missing values. And a look at the replace command leads to the realization that you're going to require t>2 since you're using L2.x in the formula.

        Comment


        • #5
          Thanks William! Such a simple fix.

          Comment

          Working...
          X