Announcement

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

  • Display fixed effects without using 'fe'

    Hello.
    I am trying to run a fixed effects model, but as I am using country dummy variables. I have set my panel to xtset: Country, Year.
    My country dummy variables are omitted because of collinearity, which makes sense.
    My model contains 3 countries, and I use Country 1 as my baseline so I omit it in my regression.

    I know that STATA computes country fixed effects when running a regression (e.g. xtreg x y Country 2 Country 3) but does not automatically display these fixed effects. What I am trying to do, is to retrieve them, and I do no know how to do this.

    Thank you in advance for your help,

    Nolan.

  • #2
    Nolan:
    Code:
    . use "https://www.stata-press.com/data/r16/nlswork.dta"
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . xtreg ln_wage c.age##c.age, fe
    
    Fixed-effects (within) regression               Number of obs     =     28,510
    Group variable: idcode                          Number of groups  =      4,710
    
    R-sq:                                           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 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |   .0539076   .0028078    19.20   0.000     .0484041    .0594112
                 |
     c.age#c.age |  -.0005973   .0000465   -12.84   0.000    -.0006885   -.0005061
                 |
           _cons |    .639913   .0408906    15.65   0.000     .5597649    .7200611
    -------------+----------------------------------------------------------------
         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
    
    . predict fe, u
    (24 missing values generated)
    
    . list fe if idcode<=2
    
           +----------+
           |       fe |
           |----------|
        1. | .4181869 |
        2. | .4181869 |
        3. | .4181869 |
        4. | .4181869 |
        5. | .4181869 |
           |----------|
        6. | .4181869 |
        7. | .4181869 |
        8. | .4181869 |
        9. | .4181869 |
       10. | .4181869 |
           |----------|
       11. | .4181869 |
       12. | .4181869 |
       13. | .0405715 |
       14. | .0405715 |
       15. | .0405715 |
           |----------|
       16. | .0405715 |
       17. | .0405715 |
       18. | .0405715 |
       19. | .0405715 |
       20. | .0405715 |
           |----------|
       21. | .0405715 |
       22. | .0405715 |
       23. | .0405715 |
       24. | .0405715 |
           +----------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Dear Carlo,

      Thank you for your rapid response.
      I ran this code with my data, but I do not really understand how to interpret the FE results. I though I would get 4 coefficients for each of my independent variables as well as for my 2 country dummy variables, but instead I have 36 values (like you have 24).
      What do they represent?
      Also, in the first code, should I be writting "Country2 and Country3" before ,fe or is there no point as they will be "omitted because of collinearity"? Or perhaps absorb(Country1) ?

      Thank you so much,

      Nolan

      Comment


      • #4
        Nolan:
        let's skim through all the issues:
        1) you -xtset- your dataset with -Country- as you -panelid-. Hence, -Country- variable should be in -long- format and should not be plugged in as a predictor in the right-hand side of your regression equation.
        2) -fe- retrieved from -xtreg,fe- is panel-specific (that is, it is the same for all the observations each panel is composed of).

        That said, sharing what you typed and what Stata gabe you back (as per FAQ) can help enormously to get a clearer picture of what's going on with your estimates (CODE delimiters, please). Thanks.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Carlo,

          I ran a Hausman test, and seem to have coefficients for each variable and seem to have identical results from my RE model and my FE model.
          Is this normal ?
          Click image for larger version

Name:	Screen Shot 2021-11-23 at 09.28.41.png
Views:	1
Size:	53.1 KB
ID:	1637722

          Comment


          • #6
            Carlo #4, I see what you mean about not using country variables they are already set. However, my aim is to compare the results from Country 2 and 3 based on Country 1's results. So ideally, I need a coefficient for Country 2 and 3 in my regression.

            Comment


            • #7
              Nolan:
              no, it isn't.
              Could you please share an example/excerpt of your dataset via -dataex-? Thanks.
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #8
                Dear Carlo,



                Code:
                 input double(lnHIVincidence lnHIVPC1 lnGDPpercapita) byte(GhanaDummy NigeriaDummy)
                10.486129722953937 15.643923344840365  5.554783656724773 1 0
                10.452724587413702  15.94944028492818  5.594767084370003 1 0
                  10.4190684378521 16.216854422981584  5.718883333917938 1 0
                10.385935955717214  16.27961908511499  5.907597390962136 1 0
                10.354018584023539 16.790836021740603  6.034303866259928 1 0
                 10.32396547214866 17.658011980733775  6.199583910418497 1 0
                10.290262353416656 17.689437018125574  6.817167166548237 1 0
                10.256741766746373 17.696930015594244  6.985795663343667 1 0
                10.232101855128423  17.88653531486476  7.104197041462478 1 0
                10.203203417520285 17.771186746313823  6.982549214380696 1 0
                10.145405520731257  18.12012955179122  7.169615731942537 1 0
                 10.07918653537561 17.663378968545718   7.34566351756438 1 0
                10.047873776565975 18.151506343056326  7.369954111132674 1 0
                10.027573631569611 18.012005488831306  7.766878791330515 1 0
                 9.966669764355146  18.13892772653089  7.549434592022792 1 0
                 9.896318614020974  17.32795111844241  7.441657623170604 1 0
                 9.858143544836176 17.552989681914273  7.556675476706391 1 0
                 9.828320087175568 17.448348621194587  7.611190253250236 1 0
                12.092766355126843 16.301666427152707  6.341999442972553 0 1
                12.063845791066543 18.448373728969113  6.380769471660136 0 1
                12.035639243543184 17.438223499815255 6.6090088806684255 0 1
                12.010385517103904 17.490265732407693   6.67882781932223 0 1
                11.989099692432648  18.01528063373179  6.915598778161861 0 1
                11.969170429576389  18.25661944914992  7.145498502528713 0 1
                 11.95132647263713 18.594398729272154  7.412416817751161 0 1
                11.942883125894058 19.190710258847435  7.540866527851108 0 1
                11.931134203938482 19.542058586373063  7.715512421877275 0 1
                 11.91533220660215  19.93008835431139  7.545038366530954 0 1
                11.907512305111593 19.892003058042945  7.732122519343664 0 1
                  11.9056837375054  20.15882844373177  7.819072873281516 0 1
                11.893023197292328 20.091558005046362  7.909791389808479 0 1
                11.868417540550082  20.23604442880359  7.993467863067233 0 1
                11.857328250462627 20.464782631417066  8.038830172427122 0 1
                11.857619771689171  20.13644610441448  7.896359252873509 0 1
                11.856652410517434 19.790520467000295  7.685244880952964 0 1
                11.859451073054725 19.849804683047612  7.585060333098358 0 1
                 11.95532602199948 16.412405709700323  6.018477309969345 0 0
                11.922277475344602 17.131331588888955 6.0076792602370555 0 0
                11.891638310309713  17.21430505501012  6.020956167481224 0 0
                11.863483308524021 17.730867997981292  6.066756905099812 0 0
                11.833190351542855 18.025858795942682  6.129614963411377 0 0
                11.799915369359258 18.379254400183218  6.199761105262344 0 0
                11.755687979426275 19.010315699712102  6.185174033340644 0 0
                11.698307263606525 19.195011519587784  6.315067727932295 0 0
                11.653988751066892 19.409463285550164  6.532902465570236 0 0
                11.608244260355658 19.803388681536834  6.544223801218114 0 0
                11.558853776460012 19.655291379808784 6.6112391865569515 0 0
                11.507311094162691 20.064290104970034 6.6611305602314665 0 0
                11.438388847814647 20.072254347629194  6.766027529523722 0 0
                 11.38928615947488  20.02954849387471  6.877707946459105 0 0
                11.310616345376374  20.21611844020177  6.937389466731637 0 0
                 11.21381622938418  20.19574495301446  6.854284195986126 0 0
                11.150858086177909  19.82442693218592  6.873684420216199 0 0
                11.078683332967628 20.073476951774687  6.912649870899865 0 0
                end

                Comment


                • #9
                  Nolan:
                  as far as the -panelid- set up is concerned, I would go as follows (you cannot -xtset- your oanel dataset properly if you have a categorical variable for each country):
                  Code:
                  . gen Country_Overall= GhanaDummy
                  
                  . label define Country_Overall 1 "Ghana"
                  
                  . replace NigeriaDummy=2 if NigeriaDummy==1
                  (18 real changes made)
                  
                  . replace Country_Overall= NigeriaDummy if NigeriaDummy==2
                  (18 real changes made)
                  
                  . label define Country_Overall 2 "Nigeria", modify
                  
                  . label val Country_Overall Country_Overall
                  
                  . xtset Country_Overall
                         panel variable:  Country_Overall (balanced)
                  
                  . xtreg lnGDPpercapita lnHIVincidence lnHIVPC1, fe
                  
                  Fixed-effects (within) regression               Number of obs     =         54
                  Group variable: Country_Ov~l                    Number of groups  =          3
                  
                  R-sq:                                           Obs per group:
                       within  = 0.7329                                         min =         18
                       between = 0.1370                                         avg =       18.0
                       overall = 0.0645                                         max =         18
                  
                                                                  F(2,49)           =      67.23
                  corr(u_i, Xb)  = -0.7435                        Prob > F          =     0.0000
                  
                  --------------------------------------------------------------------------------
                  lnGDPpercapita |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                  ---------------+----------------------------------------------------------------
                  lnHIVincidence |  -1.173936   .3027748    -3.88   0.000    -1.782385   -.5654876
                        lnHIVPC1 |    .274116   .0566344     4.84   0.000      .160305     .387927
                           _cons |   15.01598   4.216628     3.56   0.001     6.542354    23.48962
                  ---------------+----------------------------------------------------------------
                         sigma_u |  1.0821079
                         sigma_e |  .30883289
                             rho |  .92468207   (fraction of variance due to u_i)
                  --------------------------------------------------------------------------------
                  F test that all u_i=0: F(2, 49) = 50.47                      Prob > F = 0.0000
                  
                  . estimates store fe
                  
                  . xtreg lnGDPpercapita lnHIVincidence lnHIVPC1, re
                  
                  Random-effects GLS regression                   Number of obs     =         54
                  Group variable: Country_Ov~l                    Number of groups  =          3
                  
                  R-sq:                                           Obs per group:
                       within  = 0.6864                                         min =         18
                       between = 0.0141                                         avg =       18.0
                       overall = 0.4313                                         max =         18
                  
                                                                  Wald chi2(2)      =      38.68
                  corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
                  
                  --------------------------------------------------------------------------------
                  lnGDPpercapita |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                  ---------------+----------------------------------------------------------------
                  lnHIVincidence |  -.2706769   .1019956    -2.65   0.008    -.4705845   -.0707693
                        lnHIVPC1 |   .3716916   .0597655     6.22   0.000     .2545534    .4888298
                           _cons |    3.06235   1.195985     2.56   0.010     .7182619    5.406439
                  ---------------+----------------------------------------------------------------
                         sigma_u |          0
                         sigma_e |  .30883289
                             rho |          0   (fraction of variance due to u_i)
                  --------------------------------------------------------------------------------
                  
                  . xttest0
                  
                  Breusch and Pagan Lagrangian multiplier test for random effects
                  
                          lnGDPpercapita[Country_Overall,t] = Xb + u[Country_Overall] + e[Country_Overall,t]
                  
                          Estimated results:
                                           |       Var     sd = sqrt(Var)
                                  ---------+-----------------------------
                                 lnGDPpe~a |   .4744845       .6888284
                                         e |   .0953778       .3088329
                                         u |          0              0
                  
                          Test:   Var(u) = 0
                                               chibar2(01) =     0.00
                                            Prob > chibar2 =   1.0000
                  
                  . estimates store re
                  
                  . hausman fe re
                  
                                   ---- Coefficients ----
                               |      (b)          (B)            (b-B)     sqrt(diag(V_b-V_B))
                               |       fe           re         Difference          S.E.
                  -------------+----------------------------------------------------------------
                  lnHIVincid~e |   -1.173936    -.2706769       -.9032595         .285078
                      lnHIVPC1 |     .274116     .3716916       -.0975756               .
                  ------------------------------------------------------------------------------
                                             b = consistent under Ho and Ha; obtained from xtreg
                              B = inconsistent under Ha, efficient under Ho; obtained from xtreg
                  
                      Test:  Ho:  difference in coefficients not systematic
                  
                                    chi2(2) = (b-B)'[(V_b-V_B)^(-1)](b-B)
                                            =        8.53
                                  Prob>chi2 =      0.0141
                                  (V_b-V_B is not positive definite)
                  
                  .
                  In the abovementioned toy-example, being no panel-wise effect unde -xtrer,re-, -hausman- test outcome points out to -fe- specifrication.
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment


                  • #10
                    Carlo, this is amazing thank you.

                    One last question, can I get coefficients for Nigeria and Tanzania or not? I was hoping to interpret their coefficients based on Ghana (as Ghana is my baseline country).

                    Comment


                    • #11
                      Nolan:
                      you cannot get coefficients for the countries under -xtreg-, as they are your -panelid- (but you can get their panel-specific -fe-).
                      The only way you can obtain the coefficient implies switching to -regress- with -fe- (please note that -xtreg,fe- remains the way to go):
                      Code:
                      reg lnGDPpercapita lnHIVincidence lnHIVPC1 i.Country_Overall
                      Please note that -vce(cluster Country-Overall)- would be mandatory (as -regress- does not know that the observations belongng to the same panel are not independednt), but with three clusters only is not recommended.
                      Kind regards,
                      Carlo
                      (Stata 19.0)

                      Comment


                      • #12
                        Ok I get you. So to get the countries' panel specific fe I use the code
                        Code:
                        list fe if idcode<=2
                        , is that correct?
                        I then get 36 values (where the first 18 are identical and the second part of 18 values are identical) which I assume is because I have 18 years for each country?

                        Comment


                        • #13
                          Nolan:
                          correct.
                          1) you run -xtreg,fe- with -if- clause -idcode<=2-;
                          2) you retrieve panel-specifc -fe- (that is, it is the same for all the observations each panel is composed of);
                          3) if each panel is composed of 18 observations, you will have two series of 18 panel-specific -fe-.
                          Kind regards,
                          Carlo
                          (Stata 19.0)

                          Comment


                          • #14
                            Dear Carlo, thank you for this, I managed to do it.
                            I was wondering if you could help me with the interpretation of my results... I am running a fixed effects model and a Least Square Dummy variable model (the results are the same), where Ghana is my baseline country. I am unsure about how to interpret the coefficients of my explanatory variables.

                            LSDV:
                            Code:
                             reg ln100malincidence lnDAHMALPERCAP lnDAHTBPERCAP lnDAHHIVPERCAP lnGDPpercapita Governance lnGovernmentMalariaSpendingp Nigeria Tanzania
                            Are the results of DAH MAL etc... for Ghana or are they an average of Nigeria and Tanzania or ...?
                            For the dummy variables (i.e. Nigeria and Tanzania) I think this is correct: Nigeria is doing worse than Ghana in combatting malaria incidence and deaths, while Tanzania is doing better than Ghana.

                            Code:
                             
                            Model 1.A
                            Variables Malaria incidence
                            DAH MAL -1.342
                            DAH TB -0.386
                            DAHHIV -1.907
                            GDP -0.0845
                            Governance 0.412
                            GovSpen Malaria 0.133
                            Nigeria 0.468
                            Tanzania -0.303
                            Constant 14.60***
                            Observations 54
                            R-squared 0.8167
                            Adjusted R-squared 0.7841
                            Root MSE 0 .19343


                            Thank you so much,

                            Nolan.

                            Comment


                            • #15
                              Nolan:
                              according to the results you shared, other thngs being equal, andassuming that coefficients for Nigeria and Tanzania do not reach statistical significance, there's no evidence that countries play any relevant role in explaining the variation in malaria incidence.
                              As usual, reporting results by copy and pasting (and partially so) does not help positive replies.
                              Kind regards,
                              Carlo
                              (Stata 19.0)

                              Comment

                              Working...
                              X