Announcement

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

  • xtset an tsset

    Hi!

    For the construction of a certain variable, I have to do following calculation:
    Code:
    generate capitalexpenditure = (c21_28-L.c21_28+c630)/c20_58
    It is a dataset which includes various financial items over the years 2009-2018 for the firms in my sample, and I made it long. I am now wondering if I should use the xtset command or the tsset command to calculate this variable.

    thank you very much,
    Timea De Wispelaere

  • #2
    Wrong way round. You can't even refer to lagged values unless you have xtset or tsset the data successfully. In this case a firm identifier and a time (?year) variable are both required,

    xtset and tsset commands can't calculate anything for you. They just -- in this context -- allow you to use a time series operator. and ensure that separate panels are treated separately.

    Comment


    • #3
      I expressed myself in the wrong way. I mean, before being able to calculate the capitalexpenditure variable, I should let stata know he is working with a time series. I am now wondering, should I use tsset or xtset? Because I don't understand the difference.

      Comment


      • #4
        Timea:
        there's no difference for what you're after (panel data regerssion):
        Code:
        . use "https://www.stata-press.com/data/r16/nlswork.dta"
        (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
        
        . tsset idcode year
               panel variable:  idcode (unbalanced)
                time variable:  year, 68 to 88, but with gaps
                        delta:  1 unit
        
        . xtreg ln_wage age
        
        Random-effects GLS regression                   Number of obs     =     28,510
        Group variable: idcode                          Number of groups  =      4,710
        
        R-sq:                                           Obs per group:
             within  = 0.1026                                         min =          1
             between = 0.0877                                         avg =        6.1
             overall = 0.0774                                         max =         15
        
                                                        Wald chi2(1)      =    3140.35
        corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
        
        ------------------------------------------------------------------------------
             ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 age |   .0185667   .0003313    56.04   0.000     .0179174    .0192161
               _cons |   1.120439   .0112038   100.01   0.000      1.09848    1.142398
        -------------+----------------------------------------------------------------
             sigma_u |  .36972456
             sigma_e |  .30349389
                 rho |  .59743613   (fraction of variance due to u_i)
        ------------------------------------------------------------------------------
        
        . xtset idcode year
               panel variable:  idcode (unbalanced)
                time variable:  year, 68 to 88, but with gaps
                        delta:  1 unit
        
        . xtreg ln_wage age
        
        Random-effects GLS regression                   Number of obs     =     28,510
        Group variable: idcode                          Number of groups  =      4,710
        
        R-sq:                                           Obs per group:
             within  = 0.1026                                         min =          1
             between = 0.0877                                         avg =        6.1
             overall = 0.0774                                         max =         15
        
                                                        Wald chi2(1)      =    3140.35
        corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
        
        ------------------------------------------------------------------------------
             ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 age |   .0185667   .0003313    56.04   0.000     .0179174    .0192161
               _cons |   1.120439   .0112038   100.01   0.000      1.09848    1.142398
        -------------+----------------------------------------------------------------
             sigma_u |  .36972456
             sigma_e |  .30349389
                 rho |  .59743613   (fraction of variance due to u_i)
        ------------------------------------------------------------------------------
        
        .
        That said, I would go -xtset-.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          thank you both! This was very helpful.

          Comment

          Working...
          X