Announcement

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

  • No observation error in Stata

    Hello, I am having an issue with running my panel regression. STATA gives a 'no observations' error. I have checked that all values are numeric, not string. I have also checked the data very carefully, ensuring there are no mistakes. There are, however, some missing values in the dataset, but I was advised not to convert them to zero as it has been distorted by results before. Please help, I am lost - why am I seeing this error message and how can I fix it?

  • #2
    If a variable has all missing values, then you cannot include it in the regression as Stata implements listwise deletion of missing values. Consider this:

    Code:
    webuse grunfeld
    gen allmissing=.
    xtreg invest mvalue kstock allmissing, fe
    *DROP VARIABLE WITH ALL MISSING VALUES
    xtreg invest mvalue kstock, fe
    Res.:

    Code:
    . xtreg invest mvalue kstock allmissing, fe
    no observations
    r(2000);
    
    . *DROP VARIABLE WITH ALL MISSING VALUES
    
    . xtreg invest mvalue kstock, fe
    
    Fixed-effects (within) regression               Number of obs     =        200
    Group variable: company                         Number of groups  =         10
    
    R-sq:                                           Obs per group:
         within  = 0.7668                                         min =         20
         between = 0.8194                                         avg =       20.0
         overall = 0.8060                                         max =         20
    
                                                    F(2,188)          =     309.01
    corr(u_i, Xb)  = -0.1517                        Prob > F          =     0.0000
    
    ------------------------------------------------------------------------------
          invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          mvalue |   .1101238   .0118567     9.29   0.000     .0867345    .1335131
          kstock |   .3100653   .0173545    17.87   0.000     .2758308    .3442999
           _cons |  -58.74393   12.45369    -4.72   0.000    -83.31086     -34.177
    -------------+----------------------------------------------------------------
         sigma_u |  85.732501
         sigma_e |  52.767964
             rho |  .72525012   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(9, 188) = 49.18                     Prob > F = 0.0000
    
    .

    Comment


    • #3
      Another common way of losing all your observations is if you use a categorical variable to create a set of indicator (dummy) variables and don't do it correctly.

      Code:
      . * Example generated by -dataex-. For more info, type help dataex
      
      . clear
      
      . input float group
      
               group
        1. 1
        2. 2
        3. 3
        4. end
      
      . * create indicator variables: this is wrong
      
      . generate a = 1 if group==1
      (2 missing values generated)
      
      . generate b = 1 if group==2
      (2 missing values generated)
      
      . generate c = 1 if group==3
      (2 missing values generated)
      
      . * create indicator variables: this is right
      
      . generate A = group==1
      
      . generate B = group==2
      
      . generate C = group==3
      
      . * see that in every observation 2 of a, b, c are missing
      
      . * see that in every observation none of A, B, C are missing
      
      . list, clean
      
             group   a   b   c   A   B   C  
        1.       1   1   .   .   1   0   0  
        2.       2   .   1   .   0   1   0  
        3.       3   .   .   1   0   0   1  
      
      . * see what happens
      
      . table a b c
      no observations
      r(2000);
      
      . table A B C
      
      ----------------------------
                  |        C      
                  |  0   1   Total
      ------------+---------------
      A           |              
        0         |              
          B       |              
            0     |      1       1
            1     |  1           1
            Total |  1   1       2
        1         |              
          B       |              
            0     |  1           1
            Total |  1           1
        Total     |              
          B       |              
            0     |  1   1       2
            1     |  1           1
            Total |  2   1       3
      ----------------------------
      
      . * this is the best:
      
      . * don't generate indicator variables
      
      . * use factor variable notation in your model
      
      . * see help factor variables
      
      .
      Last edited by William Lisowski; 16 Feb 2022, 12:15.

      Comment


      • #4
        Thank you very much for this!

        Comment


        • #5
          what if I have successfully run fixed effect model, however SEM-ML model using XTPDML command gives me error of no observation ?

          what can I do in this regard ? I have missing values in some of the dependent and independent variables

          thanks in advance !!

          Comment

          Working...
          X