Announcement

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

  • Panel data within standard error

    Dear all,

    I have a set of panel data called u, and it looks like this:
    Code:
    year country industry     u
    -------------------------------
    2010  A         01T        1
    2010  B         01T        1.5
    2010  C         01B        1.2
    2010  A         02T         3
    2010  B         02T        2.5
    2010  C         02B       1.1
    ....
    2018  A         01T         2
    2018  B         01T        3.5
    2018  C         01B        2.1
    2018  A         02T        2.1
    2018  B         02T        1.5
    2018  C         02B        2.1
    I want to see if u's trend over time, more specifically, to see if variable u has a great within variation over time.
    Graph.png
    I have tried the following:
    Code:
     xtset upstreamness year
    I got error: repeated time values within panel
    r(451);

    I read this FAQ but I'm still not sure how to fix this problem. https://www.stata.com/support/faqs/d...d-time-values/

    Or can I just do:
    Code:
    collapse(mean) u, by(year)
    reg u year
    and see the standard error?

    Your advice would be highly appreciated.
    Last edited by Micky Lu; 04 Apr 2023, 04:36.

  • #2
    Micky:
    you can easily fix this issue by -xtset-ting your dataset with the -panelid- only.
    This workaround comes at the cost of making time-series operators unavailable (you can still add -i.year- as a predictor in the right-hand side of your regression equation, though).
    In addition, if you're intrested in a non-linear relationship between -year- and the regerssand, you may want to explore the following interaction, that replaces -i.year- (the code assumes that you go -re- with default standard errors):
    Code:
     
     xtset upstreamness xtreg uniform c.year##c.year
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Originally posted by Carlo Lazzaro View Post
      Micky:
      you can easily fix this issue by -xtset-ting your dataset with the -panelid- only.
      This workaround comes at the cost of making time-series operators unavailable (you can still add -i.year- as a predictor in the right-hand side of your regression equation, though).
      In addition, if you're intrested in a non-linear relationship between -year- and the regerssand, you may want to explore the following interaction, that replaces -i.year- (the code assumes that you go -re- with default standard errors):
      Code:
      xtset upstreamness xtreg uniform c.year##c.year
      Dear Professor Lazzaro,

      Thank you for your response!

      Yes, it works with:
      Code:
      xtset upstreamness
      But when I run:
      Code:
      xtreg upstreamness year
      or
      Code:
      xtreg upstreamness c.year##c.year
      Stata shows: the panel variable upstreamness may not be included as an independent variable
      r(198);

      Comment


      • #4
        Micky:
        Stata is right and I was wrong.
        I mistyped my previous code.
        Two amended options follow:
        Code:
        xtset industry
         xtreg upstreamness c.year##c.year
        or:
        Code:
        xtset country
         xtreg upstreamness c.year##c.year
        As an aside, please call me Carlo just like all on (and many more off) this forum do. Thanks.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Dear Carlo,
          I tried
          Code:
          xtset industry
          and
          Code:
          xtset country
          , but got error: string variables not allowed in varlist; industry/country is a string variable.
          Sorry I should have specified industry is a string variable too.

          Comment


          • #6
            Micky:
            see (carefully, as it may show nasty behaviors) -help encode-.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Originally posted by Carlo Lazzaro View Post
              Micky:
              see (carefully, as it may show nasty behaviors) -help encode-.
              Dear Carlo,
              Thank you! I tried encoding industry and It works now.
              May I ask a follow-up question for #2? In order to see the within variation of upstreamness, should I use random effect or fixed effect? How should I read the result table?

              For example:
              Code:
              Random-effects GLS regression                   Number of obs     =    917,815
              Group variable: industry_new                    Number of groups  =         25
              
              R-sq:                                           Obs per group:
                   within  = 0.0000                                         min =     27,680
                   between = 0.0001                                         avg =   36,712.6
                   overall = 0.0000                                         max =     38,025
              
                                                              Wald chi2(1)      =       1.65
              corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.1994
              
              -------------------------------------------------------------------------------
               upstreamness |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
              --------------+----------------------------------------------------------------
                       year |  -.0001876   .0001462    -1.28   0.199    -.0004741    .0000989
              c.year#c.year |          0  (omitted)
                      _cons |   2.618334   .3174491     8.25   0.000     1.996145    3.240522
              --------------+----------------------------------------------------------------
                    sigma_u |  .59397366
                    sigma_e |  .36140742
                        rho |  .72980987   (fraction of variance due to u_i)
              -------------------------------------------------------------------------------
              Does it mean that the within std. error of upstreamness over time is 0.59397366 (sigma_u)?

              Best,
              Micky

              Comment


              • #8
                MIcky:
                you have a more relevant issue to deal with.
                Yo actually have a T>N (aka long) panel dataset (25 groups (N), that is panels, were observed for a minimum of 27,680 times (T)).
                Hence, you should consider -xtregar- or -xtgls-.
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment


                • #9
                  Originally posted by Carlo Lazzaro View Post
                  MIcky:
                  you have a more relevant issue to deal with.
                  Yo actually have a T>N (aka long) panel dataset (25 groups (N), that is panels, were observed for a minimum of 27,680 times (T)).
                  Hence, you should consider -xtregar- or -xtgls-.
                  Dear Carlo,
                  Thank you very much for your help!

                  Best,
                  Micky

                  Comment

                  Working...
                  X