Announcement

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

  • First-differencing in State with country-specific time trends (i.e. factor variables)

    Hi!

    I have the following model:

    Click image for larger version

Name:	image_24393-2.png
Views:	3
Size:	9.6 KB
ID:	1632271


    I have estimated the model using several different fixed effects specifications.
    I would like to estimate the two preferred specifications I have using a First Difference estimation as a robustness test, as I was suggested to do.

    My question is simple. To run my country FEs and time FEs, I code the following:

    HTML Code:
    reghdfe ln_agprod spei_05, absorb(country_id year) vce(cluster country_id)
    or alternatively
    reg ln_agprod spei_05 i.country_id i.year, cluster(country_id)
    How does this translate in First Difference in Stata. The individual time-constant unobservables will be taken into account by the differencing, but I still need my time FEs to be included.
    I tried using the
    HTML Code:
    d.(varlist
    but I would like to see a clear example of the same model estimated with FE and with FD.

    Thanks for the help!


  • #2
    In sum, I have two specifications that I estimated using the following codes:

    HTML Code:
    1.      reghdfe ln_agprod spei_05, absorb(country_id continent_id#year) vce(cluster country_id)
    
    and     2.      reghdfe ln_agprod spei_05, absorb(country_id year country_id#c.year) vce(cluster country_id)
    which I would like to estimate using first-differences. Of course the country FEs will disappear with the FD so I do not need to include them anymore but I want to have my continent*time FEs included in the first regression and my country-specific time trends in the second regression.

    Any one know how to convert this to FD in code that Stata will accept. I tried using the D. but it doesn't work with factor variables...

    Help. I've been struggling with this for hours now.

    Comment


    • #3
      Several posts on this in the forum, e.g., https://www.statalist.org/forums/for...rst-difference

      Comment


      • #4
        Andrew Musau I've had a look at several other posts, but haven't found my answer.
        Some posts suggest using d. with the i.variables which is in fact not allowed by Stata.

        Comment


        • #5
          Yes, combining factor variables and time-series operators is not allowed. I do not use factor variables in the thread I linked. Look carefully at the code and start at

          Code:
          help xi
          to figure out how to include the interactions.

          Comment


          • #6
            Andrew Musau Hi again. I looked at both -help xi- and -help fvvarlist- but still have not found a way to convert my equation into a first-difference.

            This is the code for my regression using regular FEs:
            HTML Code:
            reg ln_agprod spei_05 i.country_id continent_id#year, vce(cluster country_id)
            What I have attempted is the following to get First-Differences:

            HTML Code:
            xi: regress D.(ln_agprod spei_05 continent_id#year), nocons cluster(country_id)
            But I get an error. How can I get rid of the #?

            Comment


            • #7
              From -help xi-

              Description

              xi expands terms containing categorical variables into indicator (also called dummy) variable sets by creating new variables and, in the second syntax
              (xi: any_stata_command), executes the specified command with the expanded terms. The dummy variables created are

              i.varname creates dummies for categorical variable varname

              i.varname1*i.varname2 creates dummies for categorical variables varname1 and varname2: all interactions and main effects

              i.varname1*varname3 creates dummies for categorical variable varname1 and continuous variable varname3: all interactions and main effects

              i.varname1|varname3 creates dummies for categorical variable varname1 and continuous variable varname3: all interactions and main effect of varname3, but no
              main effect of varname1

              Code:
              sysuse auto
              keep if inrange(turn, 33, 38)
              regress mpg weight disp turn#foreign
              xi: regress mpg weight disp i.turn*i.foreign
              Res.:

              Code:
              . regress mpg weight disp turn#foreign
              
                    Source |       SS           df       MS      Number of obs   =        30
              -------------+----------------------------------   F(13, 16)       =      2.23
                     Model |  623.802814        13  47.9848319   Prob > F        =    0.0651
                  Residual |  344.063852        16  21.5039908   R-squared       =    0.6445
              -------------+----------------------------------   Adj R-squared   =    0.3557
                     Total |  967.866667        29  33.3747126   Root MSE        =    4.6372
              
              ------------------------------------------------------------------------------
                       mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
                    weight |  -.0032328   .0051172    -0.63   0.536    -.0140809    .0076153
              displacement |   -.075553   .0814844    -0.93   0.368    -.2482923    .0971863
                           |
              turn#foreign |
               33#Foreign  |   1.675269   6.803315     0.25   0.809    -12.74711    16.09765
              34#Domestic  |   13.50237   13.55899     1.00   0.334     -15.2414    42.24614
               34#Foreign  |  -.8431862   5.371567    -0.16   0.877     -12.2304    10.54403
              35#Domestic  |   .7438859   6.115219     0.12   0.905     -12.2198    13.70757
               35#Foreign  |   3.139654    5.44529     0.58   0.572    -8.403844    14.68315
              36#Domestic  |  -1.178007   6.753832    -0.17   0.864    -15.49549    13.13948
               36#Foreign  |   -2.36508   5.144244    -0.46   0.652    -13.27039    8.540231
              37#Domestic  |   7.097666   6.186807     1.15   0.268     -6.01778    20.21311
               37#Foreign  |  -3.418538   6.769025    -0.51   0.620    -17.76823    10.93115
              38#Domestic  |   1.914232   7.014492     0.27   0.788    -12.95583    16.78429
               38#Foreign  |  -2.077102   6.869849    -0.30   0.766    -16.64053    12.48633
                           |
                     _cons |   41.22324   7.060878     5.84   0.000     26.25485    56.19164
              ------------------------------------------------------------------------------
              
              . 
              . xi: regress mpg weight disp i.turn*i.foreign
              i.turn            _Iturn_33-38        (naturally coded; _Iturn_33 omitted)
              i.foreign         _Iforeign_0-1       (naturally coded; _Iforeign_0 omitted)
              i.turn*i.fore~n   _IturXfor_#_#       (coded as above)
              
                    Source |       SS           df       MS      Number of obs   =        30
              -------------+----------------------------------   F(13, 16)       =      2.23
                     Model |  623.802814        13  47.9848319   Prob > F        =    0.0651
                  Residual |  344.063852        16  21.5039908   R-squared       =    0.6445
              -------------+----------------------------------   Adj R-squared   =    0.3557
                     Total |  967.866667        29  33.3747126   Root MSE        =    4.6372
              
              --------------------------------------------------------------------------------
                         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
              ---------------+----------------------------------------------------------------
                      weight |  -.0032328   .0051172    -0.63   0.536    -.0140809    .0076153
                displacement |   -.075553   .0814844    -0.93   0.368    -.2482923    .0971863
                   _Iturn_34 |   13.50237   13.55899     1.00   0.334     -15.2414    42.24614
                   _Iturn_35 |   .7438859   6.115219     0.12   0.905     -12.2198    13.70757
                   _Iturn_36 |  -1.178007   6.753832    -0.17   0.864    -15.49549    13.13948
                   _Iturn_37 |   7.097666   6.186807     1.15   0.268     -6.01778    20.21311
                   _Iturn_38 |   1.914232   7.014492     0.27   0.788    -12.95583    16.78429
                 _Iforeign_1 |   1.675269   6.803315     0.25   0.809    -12.74711    16.09765
              _IturXfor_34_1 |  -16.02083   13.88831    -1.15   0.266    -45.46272    13.42107
              _IturXfor_35_1 |   .7204997   8.014886     0.09   0.929     -16.2703     17.7113
              _IturXfor_36_1 |  -2.862341   8.441068    -0.34   0.739    -20.75661    15.03192
              _IturXfor_37_1 |  -12.19147   8.293925    -1.47   0.161    -29.77381    5.390864
              _IturXfor_38_1 |  -5.666602   9.036534    -0.63   0.539     -24.8232    13.48999
                       _cons |   41.22324   7.060878     5.84   0.000     26.25485    56.19164
              --------------------------------------------------------------------------------
              
              .

              Comment

              Working...
              X