Announcement

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

  • unbalanced panel with 3 fixed effect

    Greetings,

    I have an unbalanced panel data with 902 observations from 258 non randomly chosen firms in 9 Industries, 7 years, and 4 countries. I chose to use all observations and i want to include Industry, Year, Country as fixed effect in my regression. I am trying to use xtreg, fe but result in omitted variables for Industry and Country

    . xtset ID YEAR, y

    Panel variable: ID (unbalanced)
    Time variable: YEAR, 2013 to 2019, but with gaps
    Delta: 1 year

    . xtdescribe

    ID: 1, 2, ..., 285 n = 285
    YEAR: 2013, 2014, ..., 2019 T = 7
    Delta(YEAR) = 1 year
    Span(YEAR) = 7 periods
    (ID*YEAR uniquely identifies each observation)

    Distribution of T_i: min 5% 25% 50% 75% 95% max
    1 1 1 3 5 7 7

    Freq. Percent Cum. | Pattern
    ---------------------------+---------
    74 25.96 25.96 | ......1
    41 14.39 40.35 | .....11
    38 13.33 53.68 | .111111
    27 9.47 63.16 | ...1111
    24 8.42 71.58 | ....111
    21 7.37 78.95 | 1111111
    15 5.26 84.21 | ..11111
    11 3.86 88.07 | .....1.
    3 1.05 89.12 | ..11...
    31 10.88 100.00 | (other patterns)
    ---------------------------+---------
    285 100.00 | XXXXXXX

    I am still learning to use stata, so there are some question that i need to ask regarding the use of stata to my research model:

    1. regarding the xtreg, fe, Is there any solution? or i just using the regression with dummy variable: reg depvar indvar1 indvar2 indvar3 indvar4 indvar5 i.Year i.Industry i.Country? Should i check fe and re using hausman test? if the result stated that i should go with re, can i still use the i.Year i.Industry i.Country?

    2. If i use a moderating variables for example: reg depvar indvar1 indvar2 indvar1*indvar2 indvar3 indvar4 indvar5 i.Year i.Industry i.Country, is there any particular treatment that i need to address?

    3. Is there any issues that i need to consider when using the unbalanced panel data? and also how about the nonrandom selection, any additional analysis that is should do?

    thanks in advance

  • #2
    1. If I were you, I would go for the multi way fixed effects always, just by default. Assumptions are less implausible. These results are replicable through least squares dummy variable by the Frisch Waugh Lovell theorem.

    2. The marginal effect of indvar1 and indvar2 & the interpretation on these coefficients will change. I would not call that a moderating variable, just an interaction term.

    3. Wooldridge (2021) recommends using fixed effects estimation with unbalanced panel data, to allow the missingness to be correlated with the regressors.

    Comment


    • #3
      Eko:
      welcome to this forum.
      As an aside to Maxence's helpful reply, pleae note that: 1) the -fe- estimator, due to demeaning, wipes out all time-invariant variables.
      Therefore, there's no gain in including time-invariant predictors (industries and countries are not expected to change across the data waves).
      As a consequence, the -fe- estimator works at its best when your data show at least a bit of variation in your time-varying variables.
      The pooled OLS that you consider as a possible way out from the limitations of the -fe- estimator will give you collinearity problems, because it is another way to go -fe-;
      2) the best way to create interactions and categorical variables is to use -fvvarlist- notation;
      3) Stata can handle both balanced and unbalanced panels. Therefore, this is not an issue;
      4) the post estimation tests do not differ between balanced and unbalanced panel datasets. Once you have ruled out endogeneity, heteroskedasticity of the epsilon error and, much more important, the correct specification of the functional form of the regressand (via the very same procedure reported in -linktest- entry, Stata .pdf manual, to be replied by hand after-xtreg-) are called for.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Thanks for your response Maxence.
        1. If I were you, I would go for the multi way fixed effects always, just by default. Assumptions are less implausible. These results are replicable through least squares dummy variable by the Frisch Waugh Lovell theorem.
        you mean i should use:
        Code:
        xtset ID YEAR, y
        reghdfe depvar indvar1 indvar2 indvar3 indvar4 indvar5, absorb (Year Industry Country)



        2. The marginal effect of indvar1 and indvar2 & the interpretation on these coefficients will change. I would not call that a moderating variable, just an interaction term.
        sorry if it is a bit theoretical, what are the differences between interaction and moderating var? i think it is an interchangeable term




        3. Wooldridge (2021) recommends using fixed effects estimation with unbalanced panel data, to allow the missingness to be correlated with the regressors.
        is this the reference you mean?: https://www.dropbox.com/sh/zj91darud...k_20210928.pdf

        Comment


        • #5
          Thank you for your response Carlo, please help me further with no. 1 & 4

          1) the -fe- estimator, due to demeaning, wipes out all time-invariant variables. Therefore, there's no gain in including time-invariant predictors (industries and countries are not expected to change across the data waves). As a consequence, the -fe- estimator works at its best when your data show at least a bit of variation in your time-varying variables. The pooled OLS that you consider as a possible way out from the limitations of the -fe- estimator will give you collinearity problems, because it is another way to go -fe-
          So should i go with:
          Code:
          xtset ID Year, y
          xtreg depvar indvar1 indvar2 indvar3 indvar4 indvar5, fe
          or
          Code:
          xtset ID Year, y
          xtreg depvar indvar1 indvar2 indvar3 indvar4 indvar5 i.Year, fe
          what is the difference? because it produces different result. Further, should i run testparm for the i.Year?




          4) the post estimation tests do not differ between balanced and unbalanced panel datasets. Once you have ruled out endogeneity, heteroskedasticity of the epsilon error and, much more important, the correct specification of the functional form of the regressand (via the very same procedure reported in -linktest- entry, Stata .pdf manual, to be replied by hand after-xtreg-) are called for.
          Are the any stata command for the post estimation test for endogeneity?
          For heteroskedasticity, can i use vce(robust) in my xtreg, fe?
          Is there any syntax like -linktest for -xtreg, fe post estimation test? i've tried linktest after xtreg, fe but the notification: not possible after xtreg
          Last edited by eko bs; 09 Oct 2022, 10:56.

          Comment


          • #6
            Eko:
            1) I cannot replicate your experience with -xtset-:
            Code:
            . use "https://www.stata-press.com/data/r17/nlswork.dta"
            (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
            
            . xtset idcode year
            
            Panel variable: idcode (unbalanced)
             Time variable: year, 68 to 88, but with gaps
                     Delta: 1 unit
            
            . xtreg ln_wage age, fe
            
            Fixed-effects (within) regression               Number of obs     =     28,510
            Group variable: idcode                          Number of groups  =      4,710
            
            R-squared:                                      Obs per group:
                 Within  = 0.1026                                         min =          1
                 Between = 0.0877                                         avg =        6.1
                 Overall = 0.0774                                         max =         15
            
                                                            F(1,23799)        =    2720.20
            corr(u_i, Xb) = 0.0314                          Prob > F          =     0.0000
            
            ------------------------------------------------------------------------------
                 ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                     age |   .0181349   .0003477    52.16   0.000     .0174534    .0188164
                   _cons |   1.148214   .0102579   111.93   0.000     1.128107     1.16832
            -------------+----------------------------------------------------------------
                 sigma_u |  .40635023
                 sigma_e |  .30349389
                     rho |  .64192015   (fraction of variance due to u_i)
            ------------------------------------------------------------------------------
            F test that all u_i=0: F(4709, 23799) = 8.81                 Prob > F = 0.0000
            
            . xtset idcode year, y
            
            Panel variable: idcode (unbalanced)
             Time variable: year, 68 to 88, but with gaps
                     Delta: 1 year
            
            . xtreg ln_wage age, fe
            
            Fixed-effects (within) regression               Number of obs     =     28,510
            Group variable: idcode                          Number of groups  =      4,710
            
            R-squared:                                      Obs per group:
                 Within  = 0.1026                                         min =          1
                 Between = 0.0877                                         avg =        6.1
                 Overall = 0.0774                                         max =         15
            
                                                            F(1,23799)        =    2720.20
            corr(u_i, Xb) = 0.0314                          Prob > F          =     0.0000
            
            ------------------------------------------------------------------------------
                 ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                     age |   .0181349   .0003477    52.16   0.000     .0174534    .0188164
                   _cons |   1.148214   .0102579   111.93   0.000     1.128107     1.16832
            -------------+----------------------------------------------------------------
                 sigma_u |  .40635023
                 sigma_e |  .30349389
                     rho |  .64192015   (fraction of variance due to u_i)
            ------------------------------------------------------------------------------
            F test that all u_i=0: F(4709, 23799) = 8.81                 Prob > F = 0.0000
            Pleaese share an example/excerpt of your dataset via -dataex- (and please use CODE delimiters to,post what you typed and what Stata gave you back). Thanks.

            4) Actually -linktest- does nit work after -xtreg-.
            But yu can replicate -linktest- procedure by hand after -xtreg-:
            Code:
            use "https://www.stata-press.com/data/r17/nlswork.dta"
            . xtreg ln_wage age, fe
            
            Fixed-effects (within) regression               Number of obs     =     28,510
            Group variable: idcode                          Number of groups  =      4,710
            
            R-squared:                                      Obs per group:
                 Within  = 0.1026                                         min =          1
                 Between = 0.0877                                         avg =        6.1
                 Overall = 0.0774                                         max =         15
            
                                                            F(1,23799)        =    2720.20
            corr(u_i, Xb) = 0.0314                          Prob > F          =     0.0000
            
            ------------------------------------------------------------------------------
                 ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                     age |   .0181349   .0003477    52.16   0.000     .0174534    .0188164
                   _cons |   1.148214   .0102579   111.93   0.000     1.128107     1.16832
            -------------+----------------------------------------------------------------
                 sigma_u |  .40635023
                 sigma_e |  .30349389
                     rho |  .64192015   (fraction of variance due to u_i)
            ------------------------------------------------------------------------------
            F test that all u_i=0: F(4709, 23799) = 8.81                 Prob > F = 0.0000
            
            . predict fitted, xb
            (24 missing values generated)
            
            . g sq_fitted=fitted^2
            (24 missing values generated)
            
            . xtreg ln_wage fitted sq_fitted, fe
            
            Fixed-effects (within) regression               Number of obs     =     28,510
            Group variable: idcode                          Number of groups  =      4,710
            
            R-squared:                                      Obs per group:
                 Within  = 0.1087                                         min =          1
                 Between = 0.1006                                         avg =        6.1
                 Overall = 0.0865                                         max =         15
            
                                                            F(2,23798)        =    1451.88
            corr(u_i, Xb) = 0.0440                          Prob > F          =     0.0000
            
            ------------------------------------------------------------------------------
                 ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                  fitted |   7.143466    .478902    14.92   0.000     6.204788    8.082144
               sq_fitted |  -1.816243    .141469   -12.84   0.000    -2.093531   -1.538955
                   _cons |  -5.167788   .4037984   -12.80   0.000    -5.959259   -4.376317
            -------------+----------------------------------------------------------------
                 sigma_u |   .4039153
                 sigma_e |  .30245467
                     rho |  .64073314   (fraction of variance due to u_i)
            ------------------------------------------------------------------------------
            F test that all u_i=0: F(4709, 23798) = 8.74                 Prob > F = 0.0000
            
            .
            As expected, the -sq_fitted- coefficient reaches statistical significance and tell us that the functional form of the regressand is misspecified (which is not surpising at all, given the deliberately poor model specification).
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Carlo, here is example of my data:
              Code:
              . dataex industry id year depvar indvar1 indvar2 indvar3 indvar4 indvar5 indvar6 indvar7
              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input byte(industry id) float year double(depvar indvar1 indvar2 indvar3 indvar4 indvar5 indvar6 indvar7)
              7  1 2017   .02852131091195094   .108695652173913  23.4116050616377   .02381346545826308     .1369413527241954 .5548614330124239          1.019091             .000088
              7  1 2018  -.02333954751000751   .106280193236715 23.51192847038384   .02262312270240464     .1077010485518832 .5652027479250896           .989016             .000103
              7  1 2019   .07970120647839964  .1157141555008659 23.82366765259794   .01671700490105655    .01204183929530678 .7406349622975642           .891125             .000117
              4  2 2019   .01084673827002072 .09835019597119679 21.51538543798208     .103116547506245     .1238681323782458 .1460453096735289           .758189                   0
              5  3 2013  -.07361779609990535 .09903381642512077 25.80972704546836   .06295977910877415     .2289269900995236 .5084959861596743 .8134039999999999                   0
              5  3 2014  -.03184669662096758   .108695652173913 25.88547500035089   .04823263330553854   -.02678586524887876 .5401327079050899           .899455                   0
              5  3 2015  -.01340409908411645  .1111111111111111 25.91828066069906   .04697343579954562   -.03914859716639804  .541604836685007 .8317249999999999             .001167
              5  3 2016  -.03884992248104722  .1135265700483092  26.0794370862147  .009288057800513177    .01068107912880073 .5955210524273862           .853668                   0
              5  3 2017  -.01915309010036215  .0966183574879227 26.17505219059095   .01662802801436273     .2600846329867719 .5636654497097998 .8830749999999999             .000013
              5  3 2018   -.1430110890751277  .1449275362318841 26.13238519968716  -.07790603549505902    .02689784963304521 .6364466966711988           .856093           4.000e-06
              5  3 2019  -.01358515485712339  .1446996627472427 26.14378104634187   .02728080942554884 -.0009140647535642659  .666034075941817           .886838                   0
              4  4 2014  -.03789798383296197  .2415458937198068 22.24151677630591    .7024835288070654    .01444694366848795 .5917869881469714            .84278                   0
              4  4 2015   -.0424798051954662  .2705314009661836 22.07895715703556    .7539867439933705    -.1362002214459266 .5471226180613096 .8250519999999999                   0
              4  4 2016    .0933263072478713  .2657004830917875 21.99900062724625    .6032196177738824    -.2359751235880463 .4870046130738319 .8240289999999999                   0
              4  4 2017    .1300881490945562   .248792270531401 21.97139913885923    .4716318201531222      -.13549830763607 .6341896330704734 .8541240000000001                   0
              4  4 2018   -.0488129380631825  .2028985507246377 22.07208501812496    .4255094423243544    .01557192458915856 .6170514010458572 .8245290000000001                   0
              4  4 2019    .0658239364784556   .248792270531401 21.97382711970923    .3362356476956082     -.137373527332103 .6220562274776424 .7512220000000001                   0
              6  5 2019    .1082241045411386  .1036368608148756 20.94800208954319    .1302644439319564    -.3094259699131774  .119595536959554            .23778  .04258899999999999
              1  6 2019  -.09493542564789148  .1111111111111111 24.77780080338225  -.08166811980111728   -.01636855413428493 .6649091594599043           .827072                   0
              5  7 2018   -.1064054073143505 .07948227144289491 23.07464614273229   .04966622145087057   -.09432823392332104 .5694776578983127           .979809                   0
              5  8 2018  -.06806338979163666 .06982043569410264 23.44400615308565  -.06944076234155647    .05126340050320229 .8678676451450439           .639799                   0
              5  8 2019  -.08483862283841337 .03864734299516908 25.18845691411124  -.01106568159883618    .08225418597509902 .8862757542396048           .569386                   0
              4  9 2018  -.06166489519836453  .1009935283930362  21.4228280306747    .0534441247794454    -.5047276670289274 .4455085136157012           .767839                   0
              5 10 2014   -.1269993420751031  .2883738948135995 23.45089594821813    .4719725296468969  -.004062634615325205 .8405594363344511 .8608199999999999                   0
              5 10 2015  -.03624837134934188   .154361498496035 23.43033196427567    .3694621430799085     -.109235430547514 .8886043380138361 .8290649999999999                   0
              5 10 2016    .1232795283684027  .1811594202898551 23.52461882766747    .2969571611860218    -.1108530006000957 .9055522068375217            .83595                   0
              5 10 2017    -.139764502192914   .268708413089053 23.69146577724896    .2531360925039047    .07026906109910791 .9110811773081291 .9095620000000001                   0
              5 10 2018   .01138374505828563  .1872664296782426 23.80129547841714    .2482716881703963    .07998991169778574 .8915272437116248 .8987830000000001                   0
              5 10 2019  .003687323584096791  .1849649074833652 24.04402024798269    .1758340234624656   -.06343206869503769 .9190144452852667           .895123                   0
              4 11 2018  -.03408863397304622   .129979035639413 21.79709527392824    .0569610869726364     .1180084738199401 .4248521601476862 .7015939999999999              .00041
              4 11 2019   .01410608197162509  .1369975389663659 21.86247297535526    .0600923460618112     .1220547687235594  .424060204326806           .689843              .00041
              4 12 2017     .042481104308284  .0893719806763285 23.05669775805528    .1000610243298927   .001705124127721881 .3400181587610434           .898382                   0
              4 12 2018  -.05851823468382281  .1273357032175736 23.21329870723602    .1155399673209065    .06628632166704518 .3108002432099397           .874266                   0
              4 12 2019  -.01351662257242293  .1608103181113845 23.19655155637705    .1170782383353146   -.01110783111399453 .2781007721517353           .870983                   0
              8 13 2017  -.03086269768040709  .1304347826086956 25.32797273646308   .03579103322166016     .1632976627644576 .3616509389890688 .6863690000000001             .001518
              1 14 2017 -.003043119110062852  .1593063531127518 24.06475223689482   .04034862347425607     .3608928193365392 .4603052520704676 .8695499999999999             .000459
              8 15 2017  -.04488462920212573  .1351517637407711 26.46699423308801    .0346267489632806     .2142339393967794 .3900297609509834 .6978000000000002             .017738
              1 16 2016  -.01675118261447353  .1703582171178562 22.57182041676656   .05853672800262592    .07874998039945445 .2151919688503369           .879687                   0
              1 16 2017    .0404326361381832  .1850788442256859 22.67731327806966   .05161755615083454      .227827422841477 .2110663601631066           .900612             .000249
              1 16 2018    .0211311384929287  .2191231428311002 22.70334506587865   .01406194521401607     -.261455458359181 .2085070203448698           .904542             .000264
              1 16 2019     .013285866709524  .2452374441709962  22.7058009289498   .01471161281359073     .0399043429941418 .2269636651371406 .8977489999999999             .000264
              4 17 2016  -.04523838324807029 .09374715158144198 21.64785580153612    .5076432833444626     .3665681781454169 .5335910005774351           .690689                   0
              4 17 2017   .02640252261054832  .1319387476073284 21.78601219061124    .3112056051072857    -.2352498409287111 .5845548410887551            .70391                   0
              4 17 2018  -.07140687159632686 .09616261051864004 21.91423804318642     .300449951771891     .1033091891346971 .6052983921482297 .7143499999999999                   0
              4 17 2019   -.0765485833101536  .0840853158326497 22.04137472818701    .2845181742065639     .1097128930910116 .6417240836987151           .682242                   0
              1 18 2019  -.09277799931100547  .0649895178197065 21.28113405211258   -.1167301178675733     -.389011003250661 .5634038879577521 .6790489999999999 .007251000000000001
              4 19 2018 -.005081523764029173  .1051408258135083 20.53381058639612    .1816724744569997    .07609360922734151 .3306803572636857 .6133480000000001  .02653400000000001
              4 19 2019  -.01459021339660907  .1051408258135083 20.49451670302157      .16623826887441   -.02242168901582417 .3706437922171084           .619052  .02653400000000001
              3 20 2016    .1240933037479706 .01932367149758454 19.74233535697383    .1119720109911176    .06608580185321822 .3713016806185699             .6268             .039175
              3 20 2017   .08370752889084945 .03381642512077294 20.02550909428018    .1007157121604052     .1669500988998269 .4022329147176693           .649146             .039175
              3 20 2018   -1.234665846386349 .04106280193236715 20.99965218575766   -.2729403271483216     .3663126774827238 .4348848504794682           .572169             .110738
              3 20 2019  -.02089495799046898 .05291222313371616 20.88434681060744  .003420469035069216     -.240358307414627 .3810165414229482 .6284590000000001             .145104
              1 21 2018  -.02079364026696883  .1901376355847234 22.79852779279722   -.0193774964479628    -.1726310048527037 .4170768541239774 .9185269999999999             .000997
              1 21 2019  -.03604325169652869  .1541336250113937 22.89002196426076  -.03180065275459829     .2768652265519597 .4845417427414822 .9069649999999999             .000997
              4 22 2019 -.005592135751682915  .1976118858809589 22.24408501368741    .1435066606482706    -.1980415763566323 .1629264325709619            .65811             .020518
              1 23 2018    .1411791231119748  .0966183574879227 24.81285486311743    .1832630535281262   -.01427368977014106 .4376202023580573            .83958             .001626
              4 24 2018  -.04638172314958092 .05049676419651809  21.2866402029928   .07949078050012653     .1797910229719933  .279601919676686           .744539               .4841
              4 24 2019  -.09378677912860359 .08166985689545164 21.15364087211107   .01386820345335052     -.158703268015107 .2063900686339077 .6512889999999999               .4841
              8 25 2018  -.04681595958862154  .1175599307264607 23.54289907718488   .03884625263073126     .0915272318857933 .5541912370231677           .863578             .000016
              8 25 2019   -.0331887859324204  .1251481177650169 23.73546876150399   .03787216746435384    -.2103057741699394 .6576484497515553 .8474489999999999              .00021
              3 26 2019   .01486455089941987 .08454106280193237 22.77713311307237    .0127291402047953     .4449649098777886 .5352236910194289 .6847139999999999                   0
              5 27 2014   .03697350167122901  .1850788442256859 25.09150127291131   .02988255131439685    -.2205288193897521  .669463814754391           .755363                   0
              5 27 2017   -.1109363095958506  .2633078115030535 25.02813880584958   .01082508017176808     .2412904414975603 .6074841214683802 .8205949999999999                   0
              5 27 2018  -.08668593829763031  .1398687448728466 25.07914969589786   .03265386955737602    .09431244435172717 .5896069802218401           .705685                   0
              5 27 2019  -.03427146811191745  .1321666210919697 25.04538167939291   .02420999432123932    .04304829939785595 .5796096022221333 .7497970000000002                   0
              4 28 2014 .0006062749258359534 .06280193236714976 23.37543945750637   .06415199396987736   -.08113429551356012 .2169300501775149           .835752                   0
              5 29 2015   .02622431728897147   .223042566766931 22.73671065819488   .05952995080800695    -.1433442089914638 .2982428733411324           .722813                   0
              5 29 2016  .006437465815884572  .1903655090693647 22.58653608948993  -.03243040519533387    -.1586639056979123 .3093090036746378 .7468779999999999                   0
              5 29 2017   -.2793362050410468  .2832011667122414 22.38668471206072    -.423232688391683    .03568044839551753 .5119771567540649           .840098                   0
              5 30 2015  -.07256464548900547  .0623461853978671 24.83446551157576   .09202507565863445    -.0729091908266947 .7776914286557051           .924831                   0
              5 30 2016  .002518236120222062 .08121410992616898 24.79796713962808    .1024598027631004    -.0669281537082209 .7596660380992203           .938651             .000048
              3 31 2019   .05062718675050185  .1345820800291678 24.08390293464152  .002203977323040087    -.3153466037699042 .4312631329846573 .7683570000000001             .000044
              4 32 2015  .009754748963817422  .4321620636222769 22.80243101765758    .2374013896870595   -.09031176224815868 .7152323043969249           .925126                   0
              4 32 2016   -.0770204924622884  .4160514082581351 22.73437448145524    .2554014455165335   -.02470036111292782 .7405522306091938 .9182880000000001                   0
              4 32 2017 -.006642138367429253  .4327317473338802 22.88979022984415    .2455458393632294     .1569094885806352 .7569977029397855 .9175750000000001                   0
              4 32 2018    -.139867605760356  .4209962628748519 23.02213474392995    .2314073562084815     .1006724436048606  .770190307809343 .9157040000000001                   0
              4 32 2019   .02660440578814006    .47254124510072 22.94910358460839    .2468012549247439    -.0294327320832288 .7561288344413319 .8551210000000001                   0
              7 33 2018   .01609623224609671 .03864734299516908  21.9158552861691    .1928290043290048     .2289960561031717 .2930735930735927 .7981669999999998             .007174
              7 33 2019   .06405943584678699 .06740497675690457 21.90572968444508    .1676111182620834    .01664025120846567 .2252420255321111 .8066720000000001             .014306
              4 34 2019   -.1621454679693972 .08454106280193237 22.41125167996347  -.09385593938838246      .148027391901118 .7758427735442145 .7606530000000001                   0
              4 35 2019   .02650875986422465 .05797101449275362 22.03580431667223    .1197747204481839    .01654187106193405 .1640156766065143           .774038           2.000e-06
              3 36 2018   .07888007045039125   .189909762100082 22.54561941873219   .08188060979603487     .1403342117401429 .6653418182455786           .845052             .000155
              3 36 2019  -.01184126124448623  .2156822532130162 22.64038291393139   .06535333069307712    -.2392133287909244 .6391880263552832           .906099             .000155
              7 37 2019   -.1771297232871248   .108012031719989 22.29814860479381   .03803324709444812    .03379222656399457 .9281929425696844           .592505             .000495
              6 38 2014   .02912950821818591  .1104274906571871 25.97564748691781   .06628880835240987     .1337292225956094 .4215253591748109           .820336                   0
              6 38 2015 -.004499332360694754 .06257405888250843 26.11322727588371   .04095381629347827   -.07856726762899328  .492732782333734 .8269550000000001                   0
              6 38 2016   .04069430550532321 .07683893902105551 26.07686748340647   .04042846734564164   -.05340846890582138 .4482940364910324           .789482                   0
              6 38 2017   -.1024205893892836 .09351927809680066 26.07002949681911    .0396128841607565    .02224861056167559 .4008717494089835 .8415200000000002                   0
              3 39 2019  -.07149923535243245  .1562072737216298 21.39145186955266  -.01561403539320658     .4208548104566763 .2177746125222232            .21072              .05235
              3 40 2019   .02636126661747042  .2507519824993164 25.01387130365858   .03660896511961095    -.1422817859889381 .5611189913955482           .804671             .804671
              5 41 2017    .1250845644848249  .1802479263512898 25.13713138635355   .02950108635074998     .1158223198127255 .6863394422053322 .8533560000000001           1.000e-06
              5 41 2018    .1142461032507196  .2354616716798834 25.14143479244117  -.01098947457233859    .02603426753780642 .7040435360374607           .835078                   0
              4 42 2017  .005364323964044057  .1689681888615441 22.54034158255625   .08747895056044223     .2339284587611955 .2072115772866042           .465332             .092593
              4 42 2018  -.04404532355271067  .2335019597119679 22.56555067533667   .05313449320328918   -.03281103431218826 .2026321903001394 .5019180000000001              .07971
              4 42 2019  -.02249847962215117  .2525977577249111 22.51845455716293 -.005789041047973842    -.1011518971482867 .2353935459047094           .723252             .082504
              1 43 2016   .04020003935319194  .2022149302707137 22.79239731941045    .1251333390829902     .1398495602159707 .1044281436627433           .883413             .010774
              1 43 2017  -.04675232006230812  .1920973475526388 22.96398901137519    .1391898801187783     .3365432051154138 .1104757957871439 .8884479999999999             .017673
              1 43 2018  -.02071520637705528  .1517181660741956 23.04680164060822    .1281871607931637   -.07095903368956118 .1128951623652645           .867358             .014452
              1 43 2019   .04944620263905918  .1466593747151581 22.99626681667348   .09947691055698832    -.1277717360261684  .106509981243512           .827532             .015806
              2 44 2018    -.022781104359179  .1750751982499316 23.44903108435689 -.004683458609052216    .02613408542385857 .3586480581155881           .768576             .000463
              end

              Code:
              . xtset id year, y
              Code:
              Panel variable: id (unbalanced)
               Time variable: year, 2013 to 2019, but with a gap
                       Delta: 1 year


              Code:
              . xtreg depvar indvar1 indvar2 indvar3 indvar4 indvar5 indvar6 indvar7, fe
              Code:
              Fixed-effects (within) regression               Number of obs     =        100
              Group variable: id                              Number of groups  =         44
              
              R-squared:                                      Obs per group:
                   Within  = 0.4930                                         min =          1
                   Between = 0.0128                                         avg =        2.3
                   Overall = 0.0162                                         max =          7
              
                                                              F(7,49)           =       6.81
              corr(u_i, Xb) = -0.9612                         Prob > F          =     0.0000
              
              ------------------------------------------------------------------------------
                    depvar | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                   indvar1 |  -.9362826   .5654255    -1.66   0.104    -2.072548    .1999824
                   indvar2 |  -.1370725   .0826654    -1.66   0.104    -.3031948    .0290498
                   indvar3 |   .8017611   .2311133     3.47   0.001     .3373216    1.266201
                   indvar4 |  -.3951487   .1072349    -3.68   0.001    -.6106452   -.1796521
                   indvar5 |    .553992   .4464939     1.24   0.221    -.3432711    1.451255
                   indvar6 |    .375364   .4282122     0.88   0.385    -.4851606    1.235889
                   indvar7 |  -2.454464   1.696931    -1.45   0.154    -5.864574    .9556462
                     _cons |   2.716148   1.929886     1.41   0.166    -1.162103    6.594399
              -------------+----------------------------------------------------------------
                   sigma_u |   .4645678
                   sigma_e |  .12482556
                       rho |  .93266592   (fraction of variance due to u_i)
              ------------------------------------------------------------------------------
              F test that all u_i=0: F(43, 49) = 1.15                      Prob > F = 0.3144

              The result is different compare if i add i.year below
              Code:
              . xtreg depvar indvar1 indvar2 indvar3 indvar4 indvar5 indvar6 indvar7 i.year, fe
              Code:
              Fixed-effects (within) regression               Number of obs     =        100
              Group variable: id                              Number of groups  =         44
              
              R-squared:                                      Obs per group:
                   Within  = 0.6166                                         min =          1
                   Between = 0.0207                                         avg =        2.3
                   Overall = 0.0139                                         max =          7
              
                                                              F(13,43)          =       5.32
              corr(u_i, Xb) = -0.9636                         Prob > F          =     0.0000
              
              ------------------------------------------------------------------------------
                    depvar | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                   indvar1 |   -1.15434   .5486109    -2.10   0.041    -2.260719   -.0479604
                   indvar2 |  -.2020754   .0844099    -2.39   0.021    -.3723042   -.0318466
                   indvar3 |   1.125021   .2576007     4.37   0.000     .6055198    1.644523
                   indvar4 |  -.4136024   .1130909    -3.66   0.001    -.6416719   -.1855329
                   indvar5 |    .544377   .4314305     1.26   0.214    -.3256854    1.414439
                   indvar6 |   .2645136   .4151869     0.64   0.527    -.5727906    1.101818
                   indvar7 |  -1.618944   1.600436    -1.01   0.317    -4.846532    1.608644
                           |
                      year |
                     2014  |  -.0584846   .1447416    -0.40   0.688     -.350384    .2334147
                     2015  |  -.0853152   .1406793    -0.61   0.547     -.369022    .1983916
                     2016  |   .0222724   .1357289     0.16   0.870    -.2514511    .2959959
                     2017  |   .1029919   .1389794     0.74   0.463    -.1772868    .3832706
                     2018  |   .0425544   .1399989     0.30   0.763    -.2397803    .3248891
                     2019  |   .1203172   .1451757     0.83   0.412    -.1724574    .4130918
                           |
                     _cons |   4.234918    1.95573     2.17   0.036     .2908116    8.179024
              -------------+----------------------------------------------------------------
                   sigma_u |  .45682459
                   sigma_e |  .11588018
                       rho |  .93954438   (fraction of variance due to u_i)
              ------------------------------------------------------------------------------
              F test that all u_i=0: F(43, 43) = 1.44                      Prob > F = 0.1164
              Which one is correct?

              Comment


              • #8
                4) Actually -linktest- does nit work after -xtreg-.
                But yu can replicate -linktest- procedure by hand after -xtreg-:
                I also tried to replicate this procedure, and here is the result:
                Code:
                . xtreg depvar indvar1 indvar2 indvar3 indvar4 indvar5 indvar6 indvar7, fe
                
                Fixed-effects (within) regression               Number of obs     =        100
                Group variable: id                              Number of groups  =         44
                
                R-squared:                                      Obs per group:
                     Within  = 0.4930                                         min =          1
                     Between = 0.0128                                         avg =        2.3
                     Overall = 0.0162                                         max =          7
                
                                                                F(7,49)           =       6.81
                corr(u_i, Xb) = -0.9612                         Prob > F          =     0.0000
                
                ------------------------------------------------------------------------------
                      depvar | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                     indvar1 |  -.9362826   .5654255    -1.66   0.104    -2.072548    .1999824
                     indvar2 |  -.1370725   .0826654    -1.66   0.104    -.3031948    .0290498
                     indvar3 |   .8017611   .2311133     3.47   0.001     .3373216    1.266201
                     indvar4 |  -.3951487   .1072349    -3.68   0.001    -.6106452   -.1796521
                     indvar5 |    .553992   .4464939     1.24   0.221    -.3432711    1.451255
                     indvar6 |    .375364   .4282122     0.88   0.385    -.4851606    1.235889
                     indvar7 |  -2.454464   1.696931    -1.45   0.154    -5.864574    .9556462
                       _cons |   2.716148   1.929886     1.41   0.166    -1.162103    6.594399
                -------------+----------------------------------------------------------------
                     sigma_u |   .4645678
                     sigma_e |  .12482556
                         rho |  .93266592   (fraction of variance due to u_i)
                ------------------------------------------------------------------------------
                F test that all u_i=0: F(43, 49) = 1.15                      Prob > F = 0.3144
                
                . predict fitted, xb
                
                . g sq_fitted=fitted^2
                
                . xtreg depvar fitted sq_fitted, fe
                
                Fixed-effects (within) regression               Number of obs     =        100
                Group variable: id                              Number of groups  =         44
                
                R-squared:                                      Obs per group:
                     Within  = 0.5569                                         min =          1
                     Between = 0.0082                                         avg =        2.3
                     Overall = 0.0048                                         max =          7
                
                                                                F(2,54)           =      33.93
                corr(u_i, Xb) = -0.9869                         Prob > F          =     0.0000
                
                ------------------------------------------------------------------------------
                      depvar | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                      fitted |   1.038941   .1297649     8.01   0.000     .7787778    1.299104
                   sq_fitted |  -.7470039   .2677893    -2.79   0.007    -1.283889   -.2101186
                       _cons |   .1189698   .0442207     2.69   0.009     .0303126    .2076271
                -------------+----------------------------------------------------------------
                     sigma_u |  .98250935
                     sigma_e |  .11116616
                         rho |  .98735999   (fraction of variance due to u_i)
                ------------------------------------------------------------------------------
                F test that all u_i=0: F(43, 54) = 2.36                      Prob > F = 0.0015
                Is it correct? if it is correct, then my regression is also misspecified, what should i do next?

                Comment


                • #9
                  Just as a comment, definitely go for the equation in which you've included time fixed effects.

                  Comment


                  • #10
                    Eko:
                    1) you coded two different specifications and, as expected, they gave back different results. Maxence's wise advice is the way to go (i.e., include -i.year- in the right-hand side of your regression equation);
                    2) yes, it is. Go with the -i.year- code and repeat the -linktest- - like procedure. If the results remain the same, you have to include more predictors and/or interactions in the right-hand side of your regerssion equation-
                    Kind regards,
                    Carlo
                    (Stata 19.0)

                    Comment


                    • #11
                      Thank you Maxence and Carlo

                      Comment

                      Working...
                      X