Announcement

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

  • Manually computing fixed effects (panel and time variable)

    Hello Statalist,

    Like the person in this post (https://www.stata.com/statalist/arch.../msg00673.html), I am trying to manually compute fixed effects on a panel dataset, over the panel and time variable. The post asked why computing fixed effects manually yielded different results than with fixed effects regression commands. The answers for that post lied in different samples being used in xtreg and regress (and others) as a result of missing variables. This understanding has solved part of my issue, but not completely.

    The post has helped me in two instances:
    1) Manually computing panel variable (country) fixed effects, and getting the same beta coefficient as xtreg, fe
    2) Manually computing time variable (year) fixed effects, and getting the same beta coefficient as xtreg i.yr

    However, the lingering problem is that I cannot get the same beta coefficients as when running an xtreg with BOTH i.yr and fe. An example dta is below. My code is as follows. (For variable legibility: "m" in the prefix refers to mean; "d" in the prefix refers to difference; "c" in the prefix refers to country; "y" in the prefix refers to year)

    *Country fixed effects, THIS WORKS because both xtreg and regress output the same beta coefficient
    tsset countrynum yr
    egen nmiss = rmiss(dependent independent)
    bysort countrynum: egen mc_dependent=mean(dependent) if nmiss==0
    g dc_dependent=dependent-mc_dependent

    bysort countrynum: egen mc_independent=mean(independent) if nmiss==0
    g dc_independent=independent-mc_independent

    xtreg dependent independent, fe
    regress dc_dependent dc_independent


    *Year fixed effects, THIS WORKS because both xtreg and regress output the same beta coefficient

    gsort yr
    bysort yr: egen my_dependent=mean(dependent) if nmiss==0
    g dy_dependent=dependent-my_dependent

    bysort yr: egen my_independent=mean(independent)if nmiss==0
    g dy_independent=independent-my_independent

    xtreg dependent independent i.yr
    regress dy_dependent dy_independent


    * Year and country fixed effects - This is the part I have questions about, xtreg and regress do not output the same beta coefficient. This post (https://stats.stackexchange.com/ques...el-regressions) suggests that the logic behind the code I am using to compute both panel and year fixed effects is correct, and there should be no problem with the missing values (I have taken care of this above) but I've been working on this for a while, tried various combinations, and there is clearly something I'm not fully grasping.

    g dcy_dependent=dependent-my_dependent-mc_dependent
    g dcy_independent=independent-my_independent-mc_independent

    xtreg dependent independent i.yr, fe
    regress dcy_dependent dcy_independent

    Thank you very much.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(yr countrynum) float(dependent independent)
    1991 112 .021465236  .8981605
    1991 111   .3605212  .9185835
    1992 111          .  .9850195
    1992 112  .17781587  .7908565
    1993 112  .53612924  .6076079
    1993 111   .4550523 .15091026
    1994 112  .20062463  .9830886
    1994 111   .8150345  .2802703
    1995 112   .2947711  .3481235
    1995 111   .9478846  .6256541
    1996 112   .6419758 .59046483
    1996 111   .8291642  .6529766
    end
    Last edited by Clara Galeazzi; 06 Nov 2019, 14:30.

  • #2
    Thanks for the data example. The number of observations that xtreg, fe reports can be misleading. Singletons are never useful in fixed effects regressions. You have only 1 observation for 1992 resulting from your missing dependent variable, therefore you should disregard that observation when demeaning.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(yr countrynum) float(dependent independent)
    1991 112 .021465236  .8981605
    1991 111   .3605212  .9185835
    1992 111          .  .9850195
    1992 112  .17781587  .7908565
    1993 112  .53612924  .6076079
    1993 111   .4550523 .15091026
    1994 112  .20062463  .9830886
    1994 111   .8150345  .2802703
    1995 112   .2947711  .3481235
    1995 111   .9478846  .6256541
    1996 112   .6419758 .59046483
    1996 111   .8291642  .6529766
    end
    *XTREG, FE
    xtset countrynum yr
    xtreg dependent independent i.yr, fe
    *BY HAND
    preserve
    *DROP SINGLETON
    drop if yr==1992
    foreach var in dependent independent{
    bys countrynum: egen mc`var'= mean(`var')
    bys yr: egen my`var'= mean(`var')
    gen md`var'=`var' -mc`var'- my`var'
    }
    regress mddependent mdindependent 
    restore
    Res.:

    Code:
    . xtreg dependent independent i.yr, fe
    
    Fixed-effects (within) regression               Number of obs     =         11
    Group variable: countrynum                      Number of groups  =          2
    
    R-sq:                                           Obs per group:
         within  = 0.6620                                         min =          5
         between = 1.0000                                         avg =        5.5
         overall = 0.4086                                         max =          6
    
                                                    F(6,3)            =       0.98
    corr(u_i, Xb)  = 0.0212                         Prob > F          =     0.5532
    
    ------------------------------------------------------------------------------
       dependent |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
     independent |   .1200886   .4303082     0.28   0.798    -1.249344    1.489521
                 |
              yr |
           1992  |   .1817997   .3231374     0.56   0.613    -.8465679    1.210167
           1993  |    .368138   .3355437     1.10   0.353    -.6997117    1.435988
           1994  |    .350064   .2737273     1.28   0.291    -.5210585    1.221186
           1995  |     .48095   .3060145     1.57   0.214    -.4929247    1.454825
           1996  |   .5790003   .2756183     2.10   0.126    -.2981402    1.456141
                 |
           _cons |   .0654659   .4308898     0.15   0.889    -1.305818    1.436749
    -------------+----------------------------------------------------------------
         sigma_u |   .2557814
         sigma_e |  .24647644
             rho |  .51851991   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(1, 3) = 4.51                        Prob > F = 0.1238
    
    . 
    
    . 
    . regress mddependent mdindependent 
    
          Source |       SS           df       MS      Number of obs   =        10
    -------------+----------------------------------   F(1, 8)         =      0.21
           Model |  .004731461         1  .004731461   Prob > F        =    0.6607
        Residual |  .182251917         8   .02278149   R-squared       =    0.0253
    -------------+----------------------------------   Adj R-squared   =   -0.0965
           Total |  .186983378         9  .020775931   Root MSE        =    .15094
    
    -------------------------------------------------------------------------------
      mddependent |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    --------------+----------------------------------------------------------------
    mdindependent |   .1200886   .2635089     0.46   0.661    -.4875639    .7277411
            _cons |  -.4375385    .166562    -2.63   0.030    -.8216311    -.053446
    -------------------------------------------------------------------------------

    Comment


    • #3
      HI Clara,
      In addition to the advice from Andrew, keep in mind that using a 1 step demeaning process is only valid when you have well-balanced panel.
      If that is not the case, you need to "demean" the data iteratively, to be able to produce the results equivalent to the fixed effect model. Below an example
      Code:
      sysuse auto, clear
       xtile mpgq=mpg, n(5)
       xtset mpgq
       gen lprice=log(price)
       ** 1 ste demeaning
       bysort mpgq:egen double m1price=mean(price)
       bysort foreign:egen double m2price=mean(price)
       
       bysort mpgq:egen double m1trunk=mean(trunk)
       bysort foreign:egen double m2trunke=mean(trunk)
       
       gen double dmprice=price-m1price-m2price
       gen double dmtrunk=trunk-m1trunk-m2trunk
       
       reg dmprice dmtrunk
       ** Multi step demeaning
       
       bysort mpgq:egen double m_price=mean(price)
       bysort mpgq:egen double m_trunk=mean(trunk)
       gen double dm_price=price-m_price
       gen double dm_trunk=trunk-m_trunk
      
       drop m_price m_trunk
       bysort foreign:egen double m_price=mean(dm_price)
       bysort foreign:egen double m_trunk=mean(dm_trunk)
       replace dm_price=dm_price-m_price
       replace dm_trunk=dm_trunk-m_trunk
       
       reg dm_price dm_trunk
       
       forvalues i=1/5 {
       qui {
       drop m_price m_trunk
       bysort mpgq:egen double m_price=mean(dm_price)
       bysort mpgq:egen double m_trunk=mean(dm_trunk)
       replace dm_price=dm_price-m_price
       replace dm_trunk=dm_trunk-m_trunk
       sum dm_price
       drop m_price m_trunk
       bysort foreign:egen double m_price=mean(dm_price)
       bysort foreign:egen double m_trunk=mean(dm_trunk)
       replace dm_price=dm_price-m_price
       replace dm_trunk=dm_trunk-m_trunk
       }
       reg dm_price dm_trunk
       }
       
         xtreg price trunk i.foreign, fe
      ** selected output
      
       reg dm_price dm_trunk
      
            Source |       SS           df       MS      Number of obs   =        74
      -------------+----------------------------------   F(1, 72)        =      0.10
             Model |  478419.178         1  478419.178   Prob > F        =    0.7569
          Residual |   356752417        72  4954894.68   R-squared       =    0.0013
      -------------+----------------------------------   Adj R-squared   =   -0.0125
             Total |   357230836        73   4893573.1   Root MSE        =      2226
      
      ------------------------------------------------------------------------------
          dm_price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
          dm_trunk |   25.82045   83.09535     0.31   0.757    -139.8271     191.468
             _cons |  -2.62e-15   258.7625    -0.00   1.000    -515.8336    515.8336
      ------------------------------------------------------------------------------
      
      .  
      .    xtreg price trunk i.foreign, fe
      
      Fixed-effects (within) regression               Number of obs     =         74
      Group variable: mpgq                            Number of groups  =          5
      
      R-sq:                                           Obs per group:
           within  = 0.0489                                         min =         12
           between = 0.0327                                         avg =       14.8
           overall = 0.0133                                         max =         18
      
                                                      F(2,67)           =       1.72
      corr(u_i, Xb)  = -0.1047                        Prob > F          =     0.1864
      
      ------------------------------------------------------------------------------
             price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
             trunk |   25.82045   86.14013     0.30   0.765     -146.116    197.7569
                   |
           foreign |
          Foreign  |   1244.195   670.3008     1.86   0.068    -93.73143     2582.12
             _cons |   5440.155   1259.663     4.32   0.000     2925.857    7954.454
      -------------+----------------------------------------------------------------
           sigma_u |  2010.0549
           sigma_e |  2307.5231
               rho |  .43142848   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      F test that all u_i=0: F(4, 67) = 9.23                       Prob > F = 0.0000
      This iterative demeaning process is what , for example, the user-written command -regxfe- does. Alternatively. a more advanced version of this demeaning process is what -reghdfe- does as well.
      HTH
      Fernando

      Comment


      • #4
        Thank you very much Andrew and Fernando!

        According to tsset, my panel is "strongly balanced", but I will follow Fernando's advice if you believe it might be applicable here.

        Andrew's answer helped me in understanding how xtreg works. What I had previously sent you was a random sample I generated to try to pinpoint the problem. However, applying Andrew's advice to my own data, I am still unable to arrive at the same coefficients using regress versus xtreg. Again, it likely related to the sample being taken for each regression. Again, thank you very much!

        Here is the code I am using, there are no single years in my own data.

        *Demean by country and time and regress
        global all_vars r_wdi_eg_elc_accs_ru_zs ea_4_2_3_yr
        *Demean by country and time
        foreach var of global all_vars {
        bys countrynum: egen mc`var'= mean(`var')
        bys yr: egen my`var'= mean(`var')
        gen md`var'=`var' -mc`var'- my`var'
        }
        regress md_r_wdi_eg_elc_accs_ru_zs md_ea_4_2_3_yr


        Here is an example of two variables direcly from my data. These variables correspond to rural electrification rates (dependent) and a specific policy measure (independent) that should increase electrification. I hope that sending you just these two variables for this one regression is representative of the whole dataset. Also, Dataex has cut it, the original is 4000+ observations, please let me know if I should attach/send the original length.

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float yr int ea_4_2_3_yr double r_wdi_eg_elc_accs_ru_zs float countrynum
        1980 0                  . 1
        1981 0                  . 1
        1982 0                  . 1
        1983 0                  . 1
        1984 0                  . 1
        1985 0                  . 1
        1986 0                  . 1
        1987 0                  . 1
        1988 0                  . 1
        1989 0                  . 1
        1990 0                  . 1
        1991 0                  . 1
        1992 0                  . 1
        1993 0                  . 1
        1994 0                  . 1
        1995 0                  . 1
        1996 0                  . 1
        1997 0                  . 1
        1998 0                  . 1
        1999 0                  . 1
        2000 0                  . 1
        2001 0                  . 1
        2002 0                  . 1
        2003 0                  . 1
        2004 0                  . 1
        2005 0                 13 1
        2006 0 12.543863296508789 1
        2007 0 18.916223526000977 1
        2008 0               32.5 1
        2009 0 31.845155715942383 1
        2010 0 32.400001525878906 1
        2011 0  33.38011169433594 1
        2012 0  63.79999923706055 1
        2013 0 58.423667907714844 1
        2014 0  87.80000305175781 1
        2015 0  64.19999694824219 1
        2016 0  78.96107482910156 1
        2017 0                  . 1
        1980 0                  . 2
        1981 0                  . 2
        1982 0                  . 2
        1983 0                  . 2
        1984 0                  . 2
        1985 0                  . 2
        1986 0                  . 2
        1987 0                  . 2
        1988 0                  . 2
        1989 0                  . 2
        1990 0  7.518615245819092 2
        1991 0  8.330742835998535 2
        1992 0  9.121241569519043 2
        1993 0  9.887081146240234 2
        1994 0 10.622082710266113 2
        1995 0  11.32157039642334 2
        1996 0 11.980201721191406 2
        1997 0 12.593094825744629 2
        1998 0 13.154279708862305 2
        1999 0 13.657462120056152 2
        2000 0  14.09835433959961 2
        2001 0                  4 2
        2002 0 14.812106132507324 2
        2003 0 15.095589637756348 2
        2004 0 15.336596488952637 2
        2005 0 15.543924331665039 2
        2006 0 15.720918655395508 2
        2007 0  8.800000190734863 2
        2008 0 16.009374618530273 2
        2009 0 16.124128341674805 2
        2010 0 16.209957122802734 2
        2011 0                5.5 2
        2012 0 16.284297943115234 2
        2013 0 16.272235870361328 2
        2014 0                  3 2
        2015 0                  7 2
        2016 0 15.984209060668945 2
        2017 0                  . 2
        1980 .                  . 3
        1981 .                  . 3
        1982 .                  . 3
        1983 .                  . 3
        1984 .                  . 3
        1985 .                  . 3
        1986 .                  . 3
        1987 .                  . 3
        1988 .                  . 3
        1989 .                  . 3
        1990 .                  . 3
        1991 .                  . 3
        1992 .                  . 3
        1993 .                  . 3
        1994 .                  . 3
        1995 .                  . 3
        1996 .                  . 3
        1997 .                  . 3
        1998 .                  . 3
        1999 .                  . 3
        2000 .                  . 3
        2001 .                  . 3
        2002 .                  . 3
        2003 .                  . 3
        end

        Comment


        • #5
          Originally posted by Clara Galeazzi View Post
          Thank you very much Andrew and Fernando!

          According to tsset, my panel is "strongly balanced", but I will follow Fernando's advice if you believe it might be applicable here.

          Andrew's answer helped me in understanding how xtreg works. What I had previously sent you was a random sample I generated to try to pinpoint the problem. However, applying Andrew's advice to my own data, I am still unable to arrive at the same coefficients using regress versus xtreg. Again, it likely related to the sample being taken for each regression. Again, thank you very much!

          Here is the code I am using, there are no single years in my own data.

          *Demean by country and time and regress
          global all_vars r_wdi_eg_elc_accs_ru_zs ea_4_2_3_yr
          *Demean by country and time
          foreach var of global all_vars {
          bys countrynum: egen mc`var'= mean(`var')
          bys yr: egen my`var'= mean(`var')
          gen md`var'=`var' -mc`var'- my`var'
          }
          regress md_r_wdi_eg_elc_accs_ru_zs md_ea_4_2_3_yr


          Here is an example of two variables direcly from my data. These variables correspond to rural electrification rates (dependent) and a specific policy measure (independent) that should increase electrification. I hope that sending you just these two variables for this one regression is representative of the whole dataset. Also, Dataex has cut it, the original is 4000+ observations, please let me know if I should attach/send the original length.

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input float yr int ea_4_2_3_yr double r_wdi_eg_elc_accs_ru_zs float countrynum
          1980 0 . 1
          1981 0 . 1
          1982 0 . 1
          1983 0 . 1
          1984 0 . 1
          1985 0 . 1
          1986 0 . 1
          1987 0 . 1
          1988 0 . 1
          1989 0 . 1
          1990 0 . 1
          1991 0 . 1
          1992 0 . 1
          1993 0 . 1
          1994 0 . 1
          1995 0 . 1
          1996 0 . 1
          1997 0 . 1
          1998 0 . 1
          1999 0 . 1
          2000 0 . 1
          2001 0 . 1
          2002 0 . 1
          2003 0 . 1
          2004 0 . 1
          2005 0 13 1
          2006 0 12.543863296508789 1
          2007 0 18.916223526000977 1
          2008 0 32.5 1
          2009 0 31.845155715942383 1
          2010 0 32.400001525878906 1
          2011 0 33.38011169433594 1
          2012 0 63.79999923706055 1
          2013 0 58.423667907714844 1
          2014 0 87.80000305175781 1
          2015 0 64.19999694824219 1
          2016 0 78.96107482910156 1
          2017 0 . 1
          1980 0 . 2
          1981 0 . 2
          1982 0 . 2
          1983 0 . 2
          1984 0 . 2
          1985 0 . 2
          1986 0 . 2
          1987 0 . 2
          1988 0 . 2
          1989 0 . 2
          1990 0 7.518615245819092 2
          1991 0 8.330742835998535 2
          1992 0 9.121241569519043 2
          1993 0 9.887081146240234 2
          1994 0 10.622082710266113 2
          1995 0 11.32157039642334 2
          1996 0 11.980201721191406 2
          1997 0 12.593094825744629 2
          1998 0 13.154279708862305 2
          1999 0 13.657462120056152 2
          2000 0 14.09835433959961 2
          2001 0 4 2
          2002 0 14.812106132507324 2
          2003 0 15.095589637756348 2
          2004 0 15.336596488952637 2
          2005 0 15.543924331665039 2
          2006 0 15.720918655395508 2
          2007 0 8.800000190734863 2
          2008 0 16.009374618530273 2
          2009 0 16.124128341674805 2
          2010 0 16.209957122802734 2
          2011 0 5.5 2
          2012 0 16.284297943115234 2
          2013 0 16.272235870361328 2
          2014 0 3 2
          2015 0 7 2
          2016 0 15.984209060668945 2
          2017 0 . 2
          1980 . . 3
          1981 . . 3
          1982 . . 3
          1983 . . 3
          1984 . . 3
          1985 . . 3
          1986 . . 3
          1987 . . 3
          1988 . . 3
          1989 . . 3
          1990 . . 3
          1991 . . 3
          1992 . . 3
          1993 . . 3
          1994 . . 3
          1995 . . 3
          1996 . . 3
          1997 . . 3
          1998 . . 3
          1999 . . 3
          2000 . . 3
          2001 . . 3
          2002 . . 3
          2003 . . 3
          end
          Please, use this code instead of the one in post #4 (it takes into account the difference in samples as a result of missing values), thank you:

          egen nmiss = rmiss(r_wdi_eg_elc_accs_ru_zs ea_4_2_3_yr)
          *Demean by country and time and regress
          global all_vars r_wdi_eg_elc_accs_ru_zs ea_4_2_3_yr
          *Demean by country and time
          foreach var of global all_vars {
          bys countrynum: egen mc`var'= mean(`var') if nmiss==0
          bys yr: egen my`var'= mean(`var') if nmiss==0
          gen md`var'=`var' -mc`var'- my`var' if nmiss==0
          }
          regress md_r_wdi_eg_elc_accs_ru_zs md_ea_4_2_3_yr

          Comment


          • #6
            Try demeaning using xtreg,fe's sample and imposing the condition of no singletons and see if you get the same results. If not, you may need to upload your data set and specify your regression command and I or someone else can have a look. Based on my example:


            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input int(yr countrynum) float(dependent independent)
            1991 112 .021465236  .8981605
            1991 111   .3605212  .9185835
            1992 111          .  .9850195
            1992 112  .17781587  .7908565
            1993 112  .53612924  .6076079
            1993 111   .4550523 .15091026
            1994 112  .20062463  .9830886
            1994 111   .8150345  .2802703
            1995 112   .2947711  .3481235
            1995 111   .9478846  .6256541
            1996 112   .6419758 .59046483
            1996 111   .8291642  .6529766
            end
            *XTREG, FE
            xtset countrynum yr
            xtreg dependent independent i.yr, fe
            preserve
            keep if e(sample)
            bys countrynum: drop if _N==1
            bys yr: drop if _N==1
            foreach var in dependent independent{
            bys countrynum: egen mc`var'= mean(`var')
            bys yr: egen my`var'= mean(`var')
            gen md`var'=`var' -mc`var'- my`var'
            }
            regress mddependent mdindependent 
            restore
            Last edited by Andrew Musau; 07 Nov 2019, 07:11.

            Comment


            • #7
              Thank you Andrew, I incorporated the changes you suggested and am still getting a slightly different coefficient.

              Below is the code, and the data is here https://drive.google.com/open?id=1tO...A6QtzrmkxUTZmV.

              xtset countrynum yr
              rename ea_4_2_3_yr independent
              rename r_wdi_eg_elc_accs_ru_zs dependent
              xtreg dependent independent i.yr, fe
              preserve
              keep if e(sample)
              bys countrynum: drop if _N==1
              bys yr: drop if _N==1
              egen nmiss = rmiss(dependent independent)

              foreach var in dependent independent{
              bys countrynum: egen mc`var'= mean(`var') if nmiss==0
              bys yr: egen my`var'= mean(`var') if nmiss==0
              gen md`var'=`var' -mc`var'- my`var' if nmiss==0
              }
              regress mddependent mdindependent
              restore

              Comment


              • #8
                Thanks for the example data. You have an unbalanced panel, so as suggested by FernandoRios in #3, you need to demean the data iteratively.

                Code:
                rename ea_4_2_3_yr independent
                rename r_wdi_eg_elc_accs_ru_zs dependent
                xtset countrynum yr
                xtreg dependent independent i.yr, fe
                preserve
                keep if e(sample)
                bys countrynum: drop if _N==1
                bys yr: drop if _N==1
                foreach var in dependent independent{
                bys countrynum: egen mc`var'= mean(`var')
                bys yr: egen my`var'= mean(`var')
                gen md`var'=`var' -mc`var'- my`var'
                drop mc`var' my`var'
                }
                
                forvalues i=1/5 {
                qui {
                foreach var in dependent independent{
                bys countrynum: egen mc`var'= mean(md`var')
                replace md`var'=md`var' -mc`var'
                bys yr: egen my`var'= mean(md`var')
                replace md`var'=md`var' -my`var'
                drop mc`var' my`var'
                }
                }
                }
                regress mddependent mdindependent
                restore
                Res.:

                Code:
                . xtreg dependent independent i.yr, fe
                
                Fixed-effects (within) regression               Number of obs     =      1,175
                Group variable: countrynum                      Number of groups  =         53
                
                R-sq:                                           Obs per group:
                     within  = 0.4762                                         min =          4
                     between = 0.0362                                         avg =       22.2
                     overall = 0.0639                                         max =         27
                
                                                                F(27,1095)        =      36.88
                corr(u_i, Xb)  = -0.0852                        Prob > F          =     0.0000
                
                ------------------------------------------------------------------------------
                   dependent |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                 independent |   6.693191   1.519889     4.40   0.000     3.710967    9.675414
                             |
                          yr |
                       1991  |  -1.755833   2.233539    -0.79   0.432    -6.138334    2.626667
                       1992  |   2.316719   2.173772     1.07   0.287     -1.94851    6.581949
                       1993  |   .2716885   2.173493     0.13   0.901    -3.992993     4.53637
                       1994  |   2.632635   2.110369     1.25   0.212    -1.508189    6.773459
                       1995  |   3.591043    2.07146     1.73   0.083    -.4734362    7.655523
                       1996  |   4.189823   2.049179     2.04   0.041      .169062    8.210584
                       1997  |   5.916376   2.015227     2.94   0.003     1.962234    9.870518
                       1998  |    7.09116   2.007988     3.53   0.000      3.15122     11.0311
                       1999  |     7.8827   1.990717     3.96   0.000     3.976648    11.78875
                       2000  |   10.30346   1.984078     5.19   0.000     6.410433    14.19648
                       2001  |   9.518616   1.982529     4.80   0.000     5.628631     13.4086
                       2002  |   9.728206   1.964262     4.95   0.000     5.874063    13.58235
                       2003  |   11.74643   1.959167     6.00   0.000     7.902287    15.59058
                       2004  |   11.48051   1.976744     5.81   0.000     7.601873    15.35914
                       2005  |   12.81427   1.957661     6.55   0.000     8.973079    16.65546
                       2006  |   12.81315   1.964389     6.52   0.000     8.958761    16.66754
                       2007  |   14.65551   1.945682     7.53   0.000     10.83782    18.47319
                       2008  |   15.87974   1.957768     8.11   0.000     12.03834    19.72114
                       2009  |   16.15685   1.941718     8.32   0.000     12.34694    19.96676
                       2010  |   16.90108   1.951913     8.66   0.000     13.07117    20.73099
                       2011  |    17.1002   1.943824     8.80   0.000     13.28616    20.91424
                       2012  |   20.99398   1.954611    10.74   0.000     17.15877    24.82919
                       2013  |   21.31777   1.943824    10.97   0.000     17.50373    25.13181
                       2014  |   23.53254   1.957317    12.02   0.000     19.69203    27.37306
                       2015  |   24.99923   1.968338    12.70   0.000     21.13708    28.86137
                       2016  |   26.42134    1.95733    13.50   0.000      22.5808    30.26188
                             |
                       _cons |   9.917645   1.559278     6.36   0.000     6.858135    12.97715
                -------------+----------------------------------------------------------------
                     sigma_u |  21.640389
                     sigma_e |  8.1791627
                         rho |  .87500363   (fraction of variance due to u_i)
                ------------------------------------------------------------------------------
                F test that all u_i=0: F(52, 1095) = 157.53                  Prob > F = 0.0000
                
                . 
                . 
                . regress mddependent mdindependent
                
                      Source |       SS           df       MS      Number of obs   =     1,175
                -------------+----------------------------------   F(1, 1173)      =     20.77
                       Model |  1297.36027         1  1297.36027   Prob > F        =    0.0000
                    Residual |  73254.0793     1,173  62.4501954   R-squared       =    0.0174
                -------------+----------------------------------   Adj R-squared   =    0.0166
                       Total |  74551.4395     1,174   63.502078   Root MSE        =    7.9025
                
                -------------------------------------------------------------------------------
                  mddependent |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                --------------+----------------------------------------------------------------
                mdindependent |   6.693191   1.468486     4.56   0.000     3.812038    9.574344
                        _cons |   7.43e-09   .2305409     0.00   1.000    -.4523186    .4523186
                -------------------------------------------------------------------------------

                Comment


                • #9
                  Thank you both Andrew and Fernando, this has definitely given me the same coefficients, and I've been working with it over the past few days. I would like to cite the procedure of 'iterative demeaning' for unbalanced panels. I've done a search but cannot find a paper or text. Do you know where I may reference it?
                  Thank you.

                  Comment


                  • #10
                    FernandoRios will be more familiar with this literature than I am. But you could cite his Stata Journal article as an application of this approach.

                    https://journals.sagepub.com/doi/pdf...867X1501500318

                    Comment


                    • #11
                      Thank you for answering Andrew

                      Comment


                      • #12
                        I wonder why Greene (2012) [pp. 403-404] adds back the overall mean of the variable? As far as I can see the procedure above does not deduct the overall mean of the variable.


                        Click image for larger version

Name:	greene_dm.png
Views:	1
Size:	3.4 KB
ID:	1545519

                        Comment


                        • #13
                          Hi Thomas,
                          The answer may become evident if you take the expected values of the transformations:
                          Code:
                          y*_it=y_it-ey_i-ey_t+ey
                          E(y*_it)=E(y_it)-E(ey_i)-e(ey_t)+E(ey)
                          E(y*_it)=ey-ey-ey+ey=0
                          if you do not add the overal mean back, the expected value of the right-side will be twice the original mean (with the opposite sign).

                          Comment

                          Working...
                          X