Announcement

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

  • Regression industry*year fixed effect in STATA

    Hi there,
    How can I generate and run regression to control industry*year fixed effect in STATA?
    Thank you in advance!

  • #2
    Hoa:
    technically speaking, you may want to consider something along the following lines:
    Code:
    . use "https://www.stata-press.com/data/r17/nlswork.dta"
    (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
    
    . g year_industry=year*ind_code
    (341 missing values generated)
    
    . xtset idcode year_industry
    repeated time values within panel
    r(451);
    
    . xtset idcode
    
    Panel variable: idcode (unbalanced)
    
    . xtreg ln_wage c.age##c.age i.year_industry, fe vce(cluster idcode)
    
    Fixed-effects (within) regression               Number of obs     =     28,169
    Group variable: idcode                          Number of groups  =      4,694
    
    R-squared:                                      Obs per group:
         Within  = 0.1828                                         min =          1
         Between = 0.2075                                         avg =        6.0
         Overall = 0.1719                                         max =         15
    
                                                    F(170,4693)       =          .
    corr(u_i, Xb) = 0.0913                          Prob > F          =          .
    
                                  (Std. err. adjusted for 4,694 clusters in idcode)
    -------------------------------------------------------------------------------
                  |               Robust
          ln_wage | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    --------------+----------------------------------------------------------------
              age |    .065437   .0060477    10.82   0.000     .0535807    .0772933
                  |
      c.age#c.age |  -.0008458   .0000988    -8.56   0.000    -.0010395   -.0006522
                  |
    year_industry |
              69  |  -.2151244   .1116532    -1.93   0.054    -.4340171    .0037684
              70  |   .0936565   .1078587     0.87   0.385    -.1177972    .3051102
              71  |   .1750703    .121042     1.45   0.148    -.0622288    .4123694
              72  |  -.0621015   .1347583    -0.46   0.645     -.326291     .202088
              73  |   .1320197   .0746783     1.77   0.077    -.0143847    .2784242
              75  |   .2561939   .0792523     3.23   0.001     .1008221    .4115656
              77  |   .1449438   .0965875     1.50   0.134    -.0444131    .3343007
              78  |   .1407521   .0941516     1.49   0.135    -.0438292    .3253334
              80  |   .1988352   .1110053     1.79   0.073    -.0187873    .4164577
              82  |   -.001926   .0890316    -0.02   0.983    -.1764697    .1726177
              83  |   .1192486     .10569     1.13   0.259    -.0879536    .3264507
              85  |   .1415818   .1263064     1.12   0.262     -.106038    .3892016
              87  |   .2050909    .119643     1.71   0.087    -.0294655    .4396473
              88  |   .1717386   .1045222     1.64   0.100     -.033174    .3766512
             136  |   .5208783    .058937     8.84   0.000     .4053342    .6364225
             138  |   .4446881   .0569746     7.81   0.000      .332991    .5563851
             142  |   .2988656   .1012043     2.95   0.003     .1004575    .4972736
             144  |   .3230389   .0714804     4.52   0.000     .1829037    .4631741
             146  |   .3913242   .0817845     4.78   0.000     .2309881    .5516603
             150  |   .1523785   .1628553     0.94   0.349    -.1668944    .4716513
             154  |   .3331075   .1345977     2.47   0.013     .0692329    .5969821
             156  |   .3589759   .2197103     1.63   0.102    -.0717594    .7897112
             160  |   .3489823   .1502397     2.32   0.020      .054442    .6435227
             164  |   .5490549    .139797     3.93   0.000     .2749872    .8231226
             166  |   .4259425   .1126494     3.78   0.000     .2050968    .6467882
             170  |  -.0707755   .1499249    -0.47   0.637    -.3646987    .2231478
             174  |   .2156787    .084263     2.56   0.011     .0504836    .3808738
             176  |   .9085235    .378261     2.40   0.016     .1669543    1.650093
             204  |   .0248326   .1711965     0.15   0.885     -.310793    .3604582
             207  |    .389997   .1414865     2.76   0.006      .112617     .667377
             210  |    .300939   .1150671     2.62   0.009     .0753536    .5265245
             213  |   .2779948    .118374     2.35   0.019     .0459261    .5100635
             216  |   .2902304   .1073506     2.70   0.007     .0797729    .5006879
             219  |   .2870798   .0851122     3.37   0.001     .1202199    .4539397
             225  |   .1741011   .0807504     2.16   0.031     .0157923    .3324099
             231  |   .1664301   .0943804     1.76   0.078    -.0185999    .3514601
             234  |    .234718   .1611553     1.46   0.145     -.081222     .550658
             240  |   .1545278    .106733     1.45   0.148    -.0547189    .3637745
             246  |   .2096142   .1062506     1.97   0.049     .0013132    .4179152
             249  |   .2180392   .1049774     2.08   0.038     .0122342    .4238443
             255  |    .288641   .0893613     3.23   0.001     .1134508    .4638311
             261  |    .233504   .0980585     2.38   0.017     .0412632    .4257447
             264  |   .4492036   .1315862     3.41   0.001     .1912328    .7071743
             272  |   .3238391   .0574558     5.64   0.000     .2111987    .4364794
             276  |   .3785699    .057292     6.61   0.000     .2662507    .4908891
             280  |   .3467667   .0570678     6.08   0.000     .2348869    .4586464
             284  |   .3439252   .0573162     6.00   0.000     .2315585    .4562919
             288  |   .3074104   .0581815     5.28   0.000     .1933472    .4214736
             292  |   .3198939   .0583272     5.48   0.000     .2055451    .4342426
             300  |   .2682323   .0584968     4.59   0.000      .153551    .3829136
             308  |   .2856677   .0600966     4.75   0.000     .1678501    .4034852
             312  |   .3132106   .0607554     5.16   0.000     .1941014    .4323197
             320  |   .2749739   .0615764     4.47   0.000     .1542553    .3956925
             328  |   .2839539   .0627965     4.52   0.000     .1608433    .4070645
             332  |   .2911078   .0639795     4.55   0.000      .165678    .4165377
             340  |   .2994247   .0631475     4.74   0.000      .175626    .4232235
             345  |   .2862553   .0700038     4.09   0.000      .149015    .4234956
             348  |   .3196252   .0672787     4.75   0.000     .1877274     .451523
             350  |   .2686098    .065238     4.12   0.000     .1407127     .396507
             352  |   .3754444    .069154     5.43   0.000     .2398702    .5110187
             355  |   .3124303   .0649669     4.81   0.000     .1850647    .4397959
             360  |   .3851681   .0648817     5.94   0.000     .2579695    .5123667
             365  |   .3776866   .0660637     5.72   0.000     .2481708    .5072025
             375  |   .3521591   .0683131     5.16   0.000     .2182333    .4860848
             385  |   .4133773   .0683242     6.05   0.000     .2794298    .5473248
             390  |   .4452066   .0693982     6.42   0.000     .3091536    .5812597
             400  |   .4452914   .0754288     5.90   0.000     .2974155    .5931672
             408  |   .0745872   .0598057     1.25   0.212    -.0426601    .1918345
             410  |   .3830289   .0760436     5.04   0.000     .2339478      .53211
             414  |   .1303118   .0591092     2.20   0.028       .01443    .2461936
             415  |   .4577505   .0739948     6.19   0.000      .312686    .6028151
             420  |   .0815238    .058331     1.40   0.162    -.0328323    .1958799
             425  |   .5283037   .0768345     6.88   0.000     .3776719    .6789354
             426  |   .0971294   .0575936     1.69   0.092    -.0157812      .21004
             432  |   .1094456   .0587149     1.86   0.062    -.0056632    .2245544
             435  |   .5619322   .0746805     7.52   0.000     .4155233    .7083412
             438  |    .113441   .0590082     1.92   0.055    -.0022427    .2291247
             440  |     .58528   .0787695     7.43   0.000     .4308548    .7397051
             450  |   .0363949   .0601823     0.60   0.545    -.0815906    .1543805
             462  |   .0814815   .0606352     1.34   0.179    -.0373919     .200355
             468  |   .1126424   .0617441     1.82   0.068    -.0084049    .2336898
             476  |   .1567416   .0643039     2.44   0.015     .0306757    .2828075
             480  |   .1424003   .0634375     2.24   0.025      .018033    .2667677
             483  |   .1816016   .0643259     2.82   0.005     .0554926    .3077105
             490  |   .2366809   .0615478     3.85   0.000     .1160183    .3573434
             492  |   .1087102   .0634867     1.71   0.087    -.0157536    .2331739
             497  |   .2674618   .0610082     4.38   0.000     .1478571    .3870666
             498  |   .0721726    .065511     1.10   0.271    -.0562596    .2006048
             504  |   .2679617   .0603997     4.44   0.000     .1495499    .3863735
             510  |   .1128694   .0661898     1.71   0.088    -.0168936    .2426325
             511  |   .2291164   .0617936     3.71   0.000      .107972    .3502608
             522  |   .0998189   .0686988     1.45   0.146    -.0348631    .2345009
             525  |   .2080324   .0607094     3.43   0.001     .0890135    .3270513
             528  |   .1921288   .0726317     2.65   0.008     .0497365    .3345211
             539  |   .2128163   .0620517     3.43   0.001     .0911659    .3344668
             544  |   .3441324   .0904516     3.80   0.000     .1668048      .52146
             546  |   .2272568   .0638271     3.56   0.000     .1021257    .3523879
             552  |   .2077733   .0861652     2.41   0.016     .0388489    .3766976
             560  |   .1992018   .0643654     3.09   0.002     .0730155    .3253882
             568  |   .1799161   .0767435     2.34   0.019     .0294628    .3303695
             574  |   .1883749   .0648068     2.91   0.004      .061323    .3154267
             576  |   .1763003   .0676455     2.61   0.009     .0436834    .3089173
             581  |   .2075204   .0690782     3.00   0.003     .0720947    .3429461
             584  |   .2029434   .0705781     2.88   0.004     .0645773    .3413096
             595  |   .2904191   .0682749     4.25   0.000     .1565683    .4242699
             600  |   .0948139   .0895537     1.06   0.290    -.0807534    .2703811
             609  |    .311109    .072125     4.31   0.000     .1697102    .4525078
             612  |  -.2016842   .0688974    -2.93   0.003    -.3367554    -.066613
             616  |   .3460607   .0717121     4.83   0.000     .2054713    .4866502
             621  |  -.0894246   .0738252    -1.21   0.226    -.2341567    .0553075
             624  |   .2110704   .0768438     2.75   0.006     .0604204    .3617204
             630  |  -.1303852   .0681089    -1.91   0.056    -.2639106    .0031401
             639  |  -.0520332   .0655822    -0.79   0.428    -.1806051    .0765387
             640  |   .0759073    .077653     0.98   0.328    -.0763291    .2281436
             648  |  -.0617995   .0721231    -0.86   0.392    -.2031947    .0795957
             656  |   .1519032   .0690321     2.20   0.028     .0165679    .2872385
             657  |  -.1022863   .0714177    -1.43   0.152    -.2422985    .0377259
             664  |   .1164675   .0768336     1.52   0.130    -.0341624    .2670973
             675  |  -.0263705   .0677073    -0.39   0.697    -.1591085    .1063676
             680  |   .2180718   .0757426     2.88   0.004     .0695809    .3665628
             690  |   .0476264   .1774924     0.27   0.788     -.300342    .3955948
             693  |   .0233201    .068779     0.34   0.735    -.1115191    .1581592
             696  |   .1346823   .0776851     1.73   0.083     -.017617    .2869816
             700  |   .1453541   .1265886     1.15   0.251    -.1028191    .3935273
             702  |   .0461645    .071808     0.64   0.520    -.0946128    .1869419
             704  |   .2121431   .0904798     2.34   0.019     .0347602    .3895259
             710  |   .2347147    .195053     1.20   0.229    -.1476807    .6171101
             720  |   .0638993   .0738622     0.87   0.387    -.0809053    .2087039
             730  |    .056443   .1336928     0.42   0.673    -.2056578    .3185437
             738  |   .0007804   .0722979     0.01   0.991    -.1409575    .1425183
             747  |  -.0160618   .0739343    -0.22   0.828    -.1610077    .1288841
             748  |   .1566492   .0598366     2.62   0.009     .0393413    .2739571
             750  |   .1980612   .1388667     1.43   0.154    -.0741827    .4703051
             759  |   .2326681   .0573945     4.05   0.000      .120148    .3451882
             765  |   .0777132   .0774555     1.00   0.316     -.074136    .2295624
             770  |   .1902657   .0579382     3.28   0.001     .0766796    .3038518
             780  |   .2793512   .1183474     2.36   0.018     .0473346    .5113677
             781  |   .2423313   .0579311     4.18   0.000     .1287591    .3559035
             783  |   .0246129   .0816038     0.30   0.763    -.1353689    .1845946
             792  |   .2001163    .058371     3.43   0.001     .0856817    .3145509
             800  |   .0751097   .1026684     0.73   0.464    -.1261686     .276388
             803  |   .2006384   .0582127     3.45   0.001     .0865142    .3147626
             816  |   .2058093   .0715488     2.88   0.004     .0655401    .3460786
             820  |   .0972962   .0968806     1.00   0.315    -.0926351    .2872276
             825  |   .1499924   .0581145     2.58   0.010     .0360607    .2639241
             828  |   .3183524   .0663448     4.80   0.000     .1882854    .4484195
             830  |   .2714865    .123515     2.20   0.028      .029339    .5136339
             840  |   .2897824   .0653262     4.44   0.000     .1617123    .4178524
             847  |   .1406452   .0600245     2.34   0.019      .022969    .2583214
             850  |   .3091407   .1937094     1.60   0.111    -.0706206     .688902
             852  |   .3350374   .0634987     5.28   0.000     .2105502    .4595245
             858  |   .1582583   .0604261     2.62   0.009     .0397947    .2767218
             864  |   .3458952   .0657406     5.26   0.000     .2170127    .4747777
             870  |   .0496647   .1212348     0.41   0.682    -.1880124    .2873418
             876  |   .3093225   .0669572     4.62   0.000     .1780549    .4405901
             880  |   .1103371   .0614934     1.79   0.073    -.0102188     .230893
             900  |   .2392429    .063221     3.78   0.000     .1152999    .3631858
             902  |   .1204948   .0630098     1.91   0.056     -.003034    .2440235
             913  |   .1512673    .063606     2.38   0.017     .0265696     .275965
             924  |   .2719516   .0629627     4.32   0.000     .1485151     .395388
             935  |   .1785435   .0649804     2.75   0.006     .0511514    .3059357
             936  |   .2324864   .0633571     3.67   0.000     .1082768    .3566961
             957  |   .2001202   .0668775     2.99   0.003      .069009    .3312315
             960  |   .2549316   .0665642     3.83   0.000     .1244345    .3854286
             968  |   .2437592   .0685375     3.56   0.000     .1093935     .378125
             984  |     .24743   .0682748     3.62   0.000     .1135793    .3812807
             996  |   .3289204   .0708963     4.64   0.000     .1899303    .4679104
            1020  |   .3364812    .069853     4.82   0.000     .1995365     .473426
            1044  |   .3476649   .0704221     4.94   0.000     .2096046    .4857253
            1056  |   .4229399   .0732641     5.77   0.000     .2793079    .5665718
                  |
            _cons |   .3212618   .0994659     3.23   0.001     .1262619    .5162618
    --------------+----------------------------------------------------------------
          sigma_u |  .38240507
          sigma_e |  .29083786
              rho |   .6335389   (fraction of variance due to u_i)
    -------------------------------------------------------------------------------
    
    .
    The lack of the F statistics is explained at -help j_robustsingular-.
    As you can see, due to -repeated time values within panel- the dataset was -xtset- with -panelid- only. While this fix still allows to include - i.year_industry- in the right-hand side of your regression equation, it makes time-series operator, such as lags and leads, unavailable.
    It remains to be seen how to effectively disseminate the results of such a regression specification.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank Carlo so much! My regression is working. I may just add this result as an additional test as my main model is controlled firm-fixed effect.

      Comment

      Working...
      X