Announcement

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

  • Include Fixed Effects into First Difference Panel Regression

    Hello,

    I am currently working with Panel Data at the Town level, where I want to analyze the effect of manufactured cars on total_workforce in manufacturing. In my regression, I want to include time-department fixed effects. Therefore, I tried the command:
    Code:
    egen dep_year=group(Departementcode Year)
    but when I include it in the first difference regression, it says "factor variable operators not allowed". So my question is whether the command is appropriate for creating time-department fixed effects and how I can adapt my regression to display the results?

    Code:
    reg d.working_share_i d.Carsmanufactured i.dep_year
    Edit: One thing that may be unclear is that Departementcode goes from 1 to 35, however in the dataset displayed here it only shows the Towns in Departement 1

    Code:
    clear
    input str36 Town float Year double total_workforce_i float Exportexposure str2 Departementcode float dep_year
    "01001" 2002 276.06683349609375          . "01" 1
    "01001" 2007  380.1287536621094    3812.69 "01" 2
    "01001" 2012                340   960.3752 "01" 3
    "01001" 2017                370 -24.144064 "01" 4
    "01002" 2002 40.023956298828125          . "01" 1
    "01002" 2007 107.99324798583984  1661.0493 "01" 2
    "01002" 2012                104   1150.622 "01" 3
    "01002" 2017                105  -18.87968 "01" 4
    "01004" 2002  4549.923034667969          . "01" 1
    "01004" 2007      5502.69140625  1961.8445 "01" 2
    "01004" 2012   5877.88134765625  1145.6788 "01" 3
    "01004" 2017      5669.05859375  -89.41644 "01" 4
    "01005" 2002  580.2066650390625          . "01" 1
    "01005" 2007  617.4886474609375  2129.7747 "01" 2
    "01005" 2012  772.2772216796875   955.1563 "01" 3
    "01005" 2017  820.4974365234375  -216.4052 "01" 4
    "01006" 2002  28.00071144104004          . "01" 1
    "01006" 2007  52.00780487060547   824.4368 "01" 2
    "01006" 2012                 44   79.46006 "01" 3
    "01006" 2017                 55 -128.83878 "01" 4
    "01007" 2002  941.3421020507813          . "01" 1
    "01007" 2007  972.6973876953125   2970.284 "01" 2
    "01007" 2012 1089.6182861328125   1292.465 "01" 3
    "01007" 2017 1261.6883544921875  -190.2529 "01" 4
    "01008" 2002  267.9084167480469          . "01" 1
    "01008" 2007  335.5955505371094   2895.046 "01" 2
    "01008" 2012  382.7850036621094  2133.6802 "01" 3
    "01008" 2017 412.25164794921875  -74.82647 "01" 4
    "01009" 2002  112.0251693725586          . "01" 1
    "01009" 2007  134.9229278564453  2470.9934 "01" 2
    "01009" 2012 128.75967407226563   921.4941 "01" 3
    "01009" 2017 155.55555725097656  -320.7079 "01" 4
    "01010" 2002       312.17578125          . "01" 1
    "01010" 2007   392.208740234375   3345.159 "01" 2
    "01010" 2012  416.6437072753906  562.87915 "01" 3
    "01010" 2017   504.035888671875  -394.3633 "01" 4
    "01011" 2002 168.06918334960938          . "01" 1
    "01011" 2007 180.05519104003906   4923.619 "01" 2
    "01011" 2012 178.74282836914063  1028.8918 "01" 3
    "01011" 2017  132.4202117919922 -237.61505 "01" 4
    "01012" 2002 108.03669738769531          . "01" 1
    "01012" 2007 119.58914184570313   1421.367 "01" 2
    "01012" 2012 118.07074737548828   429.9386 "01" 3
    "01012" 2017 125.00069427490234 -263.41714 "01" 4
    "01013" 2002    64.005615234375          . "01" 1
    "01013" 2007 58.893245697021484  1208.4464 "01" 2
    "01013" 2012  64.79999542236328   846.5648 "01" 3
    "01013" 2017  87.36111450195313  -79.42458 "01" 4
    "01014" 2002  1612.410400390625          . "01" 1
    "01014" 2007  1650.598876953125  4477.4277 "01" 2
    "01014" 2012 1403.8167724609375   1532.635 "01" 3
    "01014" 2017  1234.072021484375 -103.77067 "01" 4
    "01015" 2002 176.01287841796875          . "01" 1
    "01015" 2007  207.9725799560547   3351.246 "01" 2
    "01015" 2012 183.82225036621094   414.3325 "01" 3
    "01015" 2017  286.8624572753906  -379.2668 "01" 4
    "01016" 2002 107.99874114990234          . "01" 1
    "01016" 2007   155.835205078125  4354.8877 "01" 2
    "01016" 2012 194.88722229003906   969.3701 "01" 3
    "01016" 2017 188.45040893554688 -388.50815 "01" 4
    "01017" 2002 144.06304931640625          . "01" 1
    "01017" 2007  176.0791778564453  3975.4546 "01" 2
    "01017" 2012                196   652.1487 "01" 3
    "01017" 2017                120  -44.58519 "01" 4
    "01019" 2002   4.00259256362915          . "01" 1
    "01019" 2007 12.285538673400879   7019.133 "01" 2
    "01019" 2012                  8  1777.5048 "01" 3
    "01019" 2017 10.833333015441895  -676.6363 "01" 4
    "01021" 2002  432.1997375488281          . "01" 1
    "01021" 2007  615.2945556640625   1640.156 "01" 2
    "01021" 2012  624.9627075195313   784.1895 "01" 3
    "01021" 2017  635.4385986328125  -71.88666 "01" 4
    "01022" 2002 436.20452880859375          . "01" 1
    "01022" 2007  468.1335144042969   3093.123 "01" 2
    "01022" 2012                376   786.6785 "01" 3
    "01022" 2017                475  -328.0293 "01" 4
    "01023" 2002                 28          . "01" 1
    "01023" 2007  42.96847152709961   87.32652 "01" 2
    "01023" 2012                 36   607.2674 "01" 3
    "01023" 2017  42.88431930541992  -74.84007 "01" 4
    "01024" 2002  948.2540893554688          . "01" 1
    "01024" 2007 1159.0120849609375  2319.6946 "01" 2
    "01024" 2012 1465.8143310546875   754.4089 "01" 3
    "01024" 2017 1497.0186767578125  166.11267 "01" 4
    "01025" 2002  1044.277587890625          . "01" 1
    "01025" 2007 1250.5247802734375   3531.588 "01" 2
    "01025" 2012 1524.2559814453125   964.1962 "01" 3
    "01025" 2017 1911.3023681640625  -2.530538 "01" 4
    "01026" 2002 316.02227783203125          . "01" 1
    "01026" 2007 330.62335205078125  3843.4214 "01" 2
    "01026" 2012 329.28802490234375  1135.8918 "01" 3
    "01026" 2017  317.5927429199219   87.65172 "01" 4
    "01027" 2002   720.371337890625          . "01" 1
    "01027" 2007 1624.3985595703125  1046.8523 "01" 2
    "01027" 2012   1667.70654296875   345.9957 "01" 3
    "01027" 2017 1976.7513427734375  -73.67876 "01" 4
    "01028" 2002  220.1243896484375          . "01" 1
    "01028" 2007  298.5760803222656   3043.449 "01" 2
    "01028" 2012  269.6224060058594   731.6243 "01" 3
    "01028" 2017 294.50640869140625 -164.81078 "01" 4
    end




    Last edited by Lea Birm; 06 Jul 2022, 03:28.

  • #2
    You might want to try and explain the problem again and copy paste what exactly you typed at Stata and what exactly Stata returned, because I did not understand what happened.

    Also the data that you provide do not include the variables you are mentioning in your regression.

    Comment


    • #3
      Lea:
      I'm not that clear with what you're after, but you may want to consider -xtreg,fe- (after a bit of surgery aimed at making some variables palatable to Stata):
      Code:
      . encode Town, g(num_Town)
      . encode Departementcode, g(num_Departementcode)
      . xtreg total_workforce_i Exportexposure i.num_Departementcode##i.dep_year i.Year, fe
      note: 1.num_Departementcode omitted because of collinearity.
      note: 1.num_Departementcode#3.dep_year omitted because of collinearity.
      note: 1.num_Departementcode#4.dep_year omitted because of collinearity.
      note: 2012.Year omitted because of collinearity.
      note: 2017.Year omitted because of collinearity.
      
      Fixed-effects (within) regression               Number of obs     =         75
      Group variable: num_Town                        Number of groups  =         25
      
      R-squared:                                      Obs per group:
           Within  = 0.1484                                         min =          3
           Between = 0.0034                                         avg =        3.0
           Overall = 0.0000                                         max =          3
      
                                                      F(3,47)           =       2.73
      corr(u_i, Xb) = -0.0267                         Prob > F          =     0.0544
      
      ----------------------------------------------------------------------------------------------
                 total_workforce_i | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
      -----------------------------+----------------------------------------------------------------
                    Exportexposure |   .0253235   .0174028     1.46   0.152    -.0096863    .0603333
                                   |
               num_Departementcode |
                               01  |          0  (omitted)
                                   |
                          dep_year |
                                3  |   87.11914   45.07709     1.93   0.059    -3.564268    177.8026
                                4  |   150.1589   60.47295     2.48   0.017     28.50299    271.8148
                                   |
      num_Departementcode#dep_year |
                             01#3  |          0  (omitted)
                             01#4  |          0  (omitted)
                                   |
                              Year |
                             2012  |          0  (omitted)
                             2017  |          0  (omitted)
                                   |
                             _cons |   601.5304   54.02083    11.14   0.000     492.8545    710.2063
      -----------------------------+----------------------------------------------------------------
                           sigma_u |  1161.2844
                           sigma_e |  105.75317
                               rho |  .99177525   (fraction of variance due to u_i)
      ----------------------------------------------------------------------------------------------
      F test that all u_i=0: F(24, 47) = 361.05                    Prob > F = 0.0000
      Some perfect collinearity issues creep up (also because of you have a Dept only in your example).
      The warning about the -fe- machinery wiping out time-invariant variables obviously applies.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X