Announcement

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

  • XTSET I need help!!

    Hello friends! I've never needed help before as I do now. I have an estimation from panel data, but when setting up the panel, I used xtset time observations (which is supposed to be the other way around), as some reviews are telling me.

    The way I did it (reversed) makes perfect sense; the coefficients and everything else come out perfectly. When I change it "as it should be," it gives random results that make no sense at all. But I'm reading the theory, and it says that the panel should be arranged in the following way:
    i1t1
    i1 t2
    i1 t3

    However, I have it ordered with time first:
    i1 t1
    i2 t1
    i3 t1
    etc.

    Im using fixed effects.

    Could this help me justify why we set up the panel the other way around and it makes sense?

  • #2
    No, I'm afraid these data structures are identical as far as xt is concerned.

    Code:
    clear
    set seed 12345
    input int(panel time)
    1 1
    2 1
    3 1
    1 2
    2 2
    3 2
    1 3
    2 3
    3 3
    end
    
    gen x = runiform()
    gen y = 2 * x + rnormal()
    
    xtset panel time
    
    xtreg y x
    
    sort panel time
    
    xtreg y x
    Code:
    Random-effects GLS regression                   Number of obs     =          9
    Group variable: panel                           Number of groups  =          3
    
    R-squared:                                      Obs per group:
         Within  = 0.4030                                         min =          3
         Between = 0.7339                                         avg =        3.0
         Overall = 0.0736                                         max =          3
    
                                                    Wald chi2(1)      =       0.56
    corr(u_i, X) = 0 (assumed)                      Prob > chi2       =     0.4560
    
    ------------------------------------------------------------------------------
               y | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
               x |   1.521823   2.041412     0.75   0.456    -2.479271    5.522916
           _cons |   .9313119   .9967577     0.93   0.350    -1.022297    2.884921
    -------------+----------------------------------------------------------------
         sigma_u |          0
         sigma_e |  1.0363245
             rho |          0   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    
    .
    . sort time panel
    
    .
    . xtreg y x
    
    Random-effects GLS regression                   Number of obs     =          9
    Group variable: panel                           Number of groups  =          3
    
    R-squared:                                      Obs per group:
         Within  = 0.4030                                         min =          3
         Between = 0.7339                                         avg =        3.0
         Overall = 0.0736                                         max =          3
    
                                                    Wald chi2(1)      =       0.56
    corr(u_i, X) = 0 (assumed)                      Prob > chi2       =     0.4560
    
    ------------------------------------------------------------------------------
               y | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
               x |   1.521823   2.041412     0.75   0.456    -2.479271    5.522916
           _cons |   .9313119   .9967577     0.93   0.350    -1.022297    2.884921
    -------------+----------------------------------------------------------------
         sigma_u |          0
         sigma_e |  1.0363245
             rho |          0   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    Last edited by Daniel Schaefer; 13 Aug 2023, 12:42. Reason: corrected small error in example code and edit for clarity

    Comment


    • #3
      Silvana:
      there is no way that you can justify swapping panelid and timevar. In fact, the only mandatory variable in -xtset- is panelvar. If your results do not make sense (whatever this may mean), double check your model specification.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X