Announcement

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

  • Repeated cross-sectional data: interaction between cohort and period

    Dear all, I am new on panel analysis and so sorry in advance if my question may sound silly.

    I created from a repeated cross-sectional dataset (11 waves) 10 groups (5 cohorts*2 genders), and I would like to add them as fixed effect in my model to show how my dependent variable (happiness) is associated with each group.

    Following some literature, I prepared the dataset as following:
    Code:
    forvalues out=1/10 {
    preserve
    collapse happi if age_male==`out', by(wave)
    gen n=`out'
    save "C:\...\col_`out'.dta", replace
    
    restore
    }
    *
    use "C:\...\col_1.dta", clear
    ...
    append using "C:\...\col_10.dta", replace
    Then I run the analysis as follows:
    Code:
    xtset n wave
    xtreg happi i.n##i.wave
    The results I obtain seems quite reasonable to me, but may you confirm if this is the proper way of specifying the model?

    In particular, I would like to ask you two things:
    - I am interested in see how the period effect has a different effect on happiness for different groups (so to speak, imagining an interaction between n and wave, which I think is feasible in this terms), how may I specify this?
    - How is it possible (if so) to define the groups also on the base of some time-varying characteristic (like education)?


    Here my data

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(wave happi n)
     1    .18431266  1
     2    .08257133  1
     3    .02890713  1
     4  -.033792093  1
     5   -.14407647  1
     6    -.0515296  1
     7    .10290183  1
     8    .17301576  1
     9    .19918926  1
    10    .18477653  1
    11    .05888418  1
     1    .27511457  2
     2    .10902543  2
     3    .05344123  2
     4 -.0008323822  2
     5   -.10063973  2
     6   -.04609436  2
     7    .15427253  2
     8     .1930108  2
     9    .21495913  2
    10   -.05401064  2
    11   -.05986743  2
     1    .19178474  3
     2   .017143734  3
     3   -.01545494  3
     4   -.09630455  3
     5   -.24729775  3
     6    -.1621294  3
     7  -.019744495  3
     8    .08696201  3
     9  -.025833797  3
    10    .08077735  3
    11  -.027652064  3
     1     .2807034  4
     2    .07198009  4
     3    .04658693  4
     4   -.06576696  4
     5   -.21026304  4
     6   -.14248309  4
     7    .08149958  4
     8    .03756344  4
     9    .04044275  4
    10   -.10320217  4
    11   -.10965457  4
     1     .1647061  5
     2  -.010444737  5
     3    -.0141777  5
     4  -.069314145  5
     5    -.2195956  5
     6   -.17248316  5
     7   .003739717  5
     8    .03931326  5
     9   -.03838405  5
    10   .067745134  5
    11   -.10316288  5
     1    .29215783  6
     2     .0893368  6
     3    .09126772  6
     4   -.02633409  6
     5   -.12508926  6
     6   -.09679314  6
     7    .09746348  6
     8    .05426073  6
     9    .07926077  6
    10   -.02303658  6
    11   -.13512973  6
     1    .14981456  7
     2  -.010028007  7
     3   -.04729141  7
     4   -.12993051  7
     5   -.25051603  7
     6    -.2172301  7
     7   -.07843793  7
     8  -.011478887  7
     9   -.03208165  7
    10   .067713656  7
    11    -.0824557  7
     1      .287295  8
     2    .09505638  8
     3    .07974623  8
     4   -.04926404  8
     5   -.20598687  8
     6     -.099515  8
     7    .04646554  8
     8    .06156417  8
     9    .04429939  8
    10   -.05420841  8
    11   -.19584143  8
     1    .16305055  9
     2    .04960753  9
     3  -.020350937  9
     4   -.08334596  9
     5     -.229174  9
     6    -.1655318  9
     7   -.07644808  9
     8    .02687024  9
     9   -.05296043  9
    10   .035411663  9
    11   -.02516546  9
     1    .24150567 10
    end

    Really thanks a lot.

    Cheers, Giorgio

  • #2
    Anyone with some tip on that?

    Comment


    • #3
      Giorgio:
      1) you seem to want to interact the -panelid- with the -timevar-; this approach, which is far from usual, will produce perfect collinearity issues as well as model overfitting, as you can see from what follows:
      Code:
      . xtset n wave
             panel variable:  n (unbalanced)
              time variable:  wave, 1 to 11
                      delta:  1 unit
      
      . xtreg happi i.n##i.wave
      note: 9.n#11.wave omitted because of collinearity
      note: 10.n#2.wave identifies no observations in the sample
      note: 10.n#3.wave identifies no observations in the sample
      note: 10.n#4.wave identifies no observations in the sample
      note: 10.n#5.wave identifies no observations in the sample
      note: 10.n#6.wave identifies no observations in the sample
      note: 10.n#7.wave identifies no observations in the sample
      note: 10.n#8.wave identifies no observations in the sample
      note: 10.n#9.wave identifies no observations in the sample
      note: 10.n#10.wave identifies no observations in the sample
      note: 10.n#11.wave identifies no observations in the sample
      
      Random-effects GLS regression                   Number of obs     =        100
      Group variable: n                               Number of groups  =         10
      
      R-sq:                                           Obs per group:
           within  = 0.9993                                         min =          1
           between = 1.0000                                         avg =       10.0
           overall = 0.9994                                         max =         11
      
                                                      Wald chi2(98)     =    1609.78
      corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
      
      ------------------------------------------------------------------------------
             happi |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
                 n |
                2  |    .075105     .04153     1.81   0.071    -.0062924    .1565024
                3  |  -.0082248     .04153    -0.20   0.843    -.0896222    .0731726
                4  |   .0806939     .04153     1.94   0.052    -.0007035    .1620913
                5  |  -.0353034     .04153    -0.85   0.395    -.1167008     .046094
                6  |   .0921483     .04153     2.22   0.026     .0107509    .1735457
                7  |   -.050195     .04153    -1.21   0.227    -.1315924    .0312024
                8  |   .0872855     .04153     2.10   0.036     .0058881    .1686829
                9  |  -.0526559   .0313938    -1.68   0.093    -.1141865    .0088748
               10  |   .0414961     .04153     1.00   0.318    -.0399013    .1228935
                   |
              wave |
                2  |  -.1174382     .04153    -2.83   0.005    -.1988356   -.0360408
                3  |  -.1711024     .04153    -4.12   0.000    -.2524998    -.089705
                4  |  -.2338016     .04153    -5.63   0.000     -.315199   -.1524042
                5  |   -.344086     .04153    -8.29   0.000    -.4254834   -.2626886
                6  |  -.2515391     .04153    -6.06   0.000    -.3329365   -.1701417
                7  |  -.0971077     .04153    -2.34   0.019    -.1785051   -.0157103
                8  |  -.0269938     .04153    -0.65   0.516    -.1083912    .0544036
                9  |  -.0008203     .04153    -0.02   0.984    -.0822177    .0805771
               10  |   -.015233     .04153    -0.37   0.714    -.0966304    .0661644
               11  |  -.1568222   .0313938    -5.00   0.000    -.2183529   -.0952916
                   |
            n#wave |
             2  2  |  -.0486509   .0607938    -0.80   0.424    -.1678045    .0705027
             2  3  |  -.0505709   .0607938    -0.83   0.405    -.1697245    .0685827
             2  4  |  -.0421453   .0607938    -0.69   0.488    -.1612989    .0770083
             2  5  |  -.0316683   .0607938    -0.52   0.602    -.1508219    .0874853
             2  6  |  -.0696698   .0607938    -1.15   0.252    -.1888234    .0494838
             2  7  |  -.0237343   .0607938    -0.39   0.696    -.1428879    .0954193
             2  8  |    -.05511   .0607938    -0.91   0.365    -.1742636    .0640436
             2  9  |  -.0593352   .0607938    -0.98   0.329    -.1784887    .0598184
             2 10  |  -.3138922   .0607938    -5.16   0.000    -.4330458   -.1947386
             2 11  |  -.1781598   .0543756    -3.28   0.001     -.284734   -.0715855
             3  2  |  -.0572028   .0607938    -0.94   0.347    -.1763564    .0619508
             3  3  |  -.0361373   .0607938    -0.59   0.552    -.1552909    .0830163
             3  4  |  -.0542877   .0607938    -0.89   0.372    -.1734412    .0648659
             3  5  |  -.0949965   .0607938    -1.56   0.118    -.2141501    .0241571
             3  6  |   -.102375   .0607938    -1.68   0.092    -.2215286    .0167786
             3  7  |  -.1144215   .0607938    -1.88   0.060    -.2335751    .0047321
             3  8  |   -.077829   .0607938    -1.28   0.200    -.1969825    .0413246
             3  9  |  -.2167983   .0607938    -3.57   0.000    -.3359518   -.0976447
             3 10  |  -.0957744   .0607938    -1.58   0.115     -.214928    .0233792
             3 11  |  -.0626146   .0543756    -1.15   0.250    -.1691888    .0439596
             4  2  |  -.0912851   .0607938    -1.50   0.133    -.2104387    .0278685
             4  3  |  -.0630141   .0607938    -1.04   0.300    -.1821676    .0561395
             4  4  |  -.1126687   .0607938    -1.85   0.064    -.2318223    .0064849
             4  5  |  -.1468804   .0607938    -2.42   0.016     -.266034   -.0277268
             4  6  |  -.1716473   .0607938    -2.82   0.005    -.2908009   -.0524937
             4  7  |  -.1020961   .0607938    -1.68   0.093    -.2212497    .0170575
             4  8  |  -.2161462   .0607938    -3.56   0.000    -.3352998   -.0969926
             4  9  |  -.2394404   .0607938    -3.94   0.000     -.358594   -.1202868
             4 10  |  -.3686726   .0607938    -6.06   0.000    -.4878261    -.249519
             4 11  |  -.2335357   .0543756    -4.29   0.000    -.3401099   -.1269615
             5  2  |  -.0577126   .0607938    -0.95   0.342    -.1768662     .061441
             5  3  |  -.0077814   .0607938    -0.13   0.898     -.126935    .1113722
             5  4  |  -.0002186   .0607938    -0.00   0.997    -.1193722     .118935
             5  5  |  -.0402157   .0607938    -0.66   0.508    -.1593693    .0789379
             5  6  |  -.0856501   .0607938    -1.41   0.159    -.2048037    .0335035
             5  7  |  -.0638587   .0607938    -1.05   0.294    -.1830123    .0552949
             5  8  |  -.0983991   .0607938    -1.62   0.106    -.2175526    .0207545
             5  9  |  -.2022699   .0607938    -3.33   0.001    -.3214235   -.0831163
             5 10  |   -.081728   .0607938    -1.34   0.179    -.2008815    .0374256
             5 11  |  -.1110467   .0543756    -2.04   0.041    -.2176209   -.0044725
             6  2  |  -.0853828   .0607938    -1.40   0.160    -.2045364    .0337708
             6  3  |  -.0297877   .0607938    -0.49   0.624    -.1489413    .0893659
             6  4  |  -.0846903   .0607938    -1.39   0.164    -.2038439    .0344633
             6  5  |  -.0731611   .0607938    -1.20   0.229    -.1923147    .0459925
             6  6  |  -.1374118   .0607938    -2.26   0.024    -.2565654   -.0182582
             6  7  |  -.0975866   .0607938    -1.61   0.108    -.2167402     .021567
             6  8  |  -.2109033   .0607938    -3.47   0.001    -.3300569   -.0917497
             6  9  |  -.2120768   .0607938    -3.49   0.000    -.3312304   -.0929232
             6 10  |  -.2999614   .0607938    -4.93   0.000     -.419115   -.1808078
             6 11  |  -.2704653   .0543756    -4.97   0.000    -.3770395   -.1638911
             7  2  |  -.0424044   .0607938    -0.70   0.485    -.1615579    .0767492
             7  3  |  -.0260036   .0607938    -0.43   0.669    -.1451572      .09315
             7  4  |  -.0459434   .0607938    -0.76   0.450     -.165097    .0732102
             7  5  |  -.0562446   .0607938    -0.93   0.355    -.1753982     .062909
             7  6  |  -.1155055   .0607938    -1.90   0.057    -.2346591    .0036481
             7  7  |  -.1311448   .0607938    -2.16   0.031    -.2502984   -.0119912
             7  8  |  -.1342997   .0607938    -2.21   0.027    -.2534533   -.0151461
             7  9  |  -.1810759   .0607938    -2.98   0.003    -.3002295   -.0619223
             7 10  |  -.0668679   .0607938    -1.10   0.271    -.1860215    .0522857
             7 11  |   -.075448   .0543756    -1.39   0.165    -.1820222    .0311262
             8  2  |  -.0748004   .0607938    -1.23   0.219     -.193954    .0443532
             8  3  |  -.0364464   .0607938    -0.60   0.549       -.1556    .0827072
             8  4  |  -.1027574   .0607938    -1.69   0.091     -.221911    .0163962
             8  5  |  -.1491959   .0607938    -2.45   0.014    -.2683495   -.0300423
             8  6  |  -.1352709   .0607938    -2.23   0.026    -.2544245   -.0161173
             8  7  |  -.1437218   .0607938    -2.36   0.018    -.2628754   -.0245682
             8  8  |  -.1987371   .0607938    -3.27   0.001    -.3178907   -.0795835
             8  9  |  -.2421753   .0607938    -3.98   0.000    -.3613289   -.1230218
             8 10  |  -.3262704   .0607938    -5.37   0.000     -.445424   -.2071168
             8 11  |  -.3263142   .0543756    -6.00   0.000    -.4328884     -.21974
             9  2  |   .0196921   .0543756     0.36   0.717    -.0868821    .1262663
             9  3  |   .0033978   .0543756     0.06   0.950    -.1031764     .109972
             9  4  |    .003102   .0543756     0.06   0.955    -.1034722    .1096762
             9  5  |  -.0324417   .0543756    -0.60   0.551    -.1390159    .0741325
             9  6  |  -.0613463   .0543756    -1.13   0.259    -.1679205    .0452279
             9  7  |   -.126694   .0543756    -2.33   0.020    -.2332683   -.0201198
             9  8  |  -.0934896   .0543756    -1.72   0.086    -.2000639    .0130846
             9  9  |  -.1994938   .0543756    -3.67   0.000     -.306068   -.0929196
             9 10  |   -.096709   .0543756    -1.78   0.075    -.2032832    .0098652
             9 11  |          0  (omitted)
            10  2  |          0  (empty)
            10  3  |          0  (empty)
            10  4  |          0  (empty)
            10  5  |          0  (empty)
            10  6  |          0  (empty)
            10  7  |          0  (empty)
            10  8  |          0  (empty)
            10  9  |          0  (empty)
            10 10  |          0  (empty)
            10 11  |          0  (empty)
                   |
             _cons |   .2000095   .0271878     7.36   0.000     .1467224    .2532966
      -------------+----------------------------------------------------------------
           sigma_u |          0
           sigma_e |  .03139377
               rho |          0   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      At the top of that, this approach gives no evidence at all of a panel-wise effect (sigma_u=0).

      2) in your post you mentioned fixed effet but you coded its ransom counterpart. That said, when you switch to -fe- specification, the outcome as expected, let you down even more:
      Code:
      . xtreg happi i.n##i.wave, fe
      note: 2.n omitted because of collinearity
      note: 3.n omitted because of collinearity
      note: 4.n omitted because of collinearity
      note: 5.n omitted because of collinearity
      note: 6.n omitted because of collinearity
      note: 7.n omitted because of collinearity
      note: 8.n omitted because of collinearity
      note: 9.n omitted because of collinearity
      note: 10.n omitted because of collinearity
      note: 10.n#2.wave identifies no observations in the sample
      note: 10.n#3.wave identifies no observations in the sample
      note: 10.n#4.wave identifies no observations in the sample
      note: 10.n#5.wave identifies no observations in the sample
      note: 10.n#6.wave identifies no observations in the sample
      note: 10.n#7.wave identifies no observations in the sample
      note: 10.n#8.wave identifies no observations in the sample
      note: 10.n#9.wave identifies no observations in the sample
      note: 10.n#10.wave identifies no observations in the sample
      note: 10.n#11.wave identifies no observations in the sample
      
      Fixed-effects (within) regression               Number of obs     =        100
      Group variable: n                               Number of groups  =         10
      
      R-sq:                                           Obs per group:
           within  = 1.0000                                         min =          1
           between = 0.6041                                         avg =       10.0
           overall = 0.8089                                         max =         11
      
                                                      F(90,0)           =          .
      corr(u_i, Xb)  = -0.2716                        Prob > F          =          .
      
      ------------------------------------------------------------------------------
             happi |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
                 n |
                2  |          0  (omitted)
                3  |          0  (omitted)
                4  |          0  (omitted)
                5  |          0  (omitted)
                6  |          0  (omitted)
                7  |          0  (omitted)
                8  |          0  (omitted)
                9  |          0  (omitted)
               10  |          0  (omitted)
                   |
              wave |
                2  |  -.1017413          .        .       .            .           .
                3  |  -.1554055          .        .       .            .           .
                4  |  -.2181047          .        .       .            .           .
                5  |  -.3283891          .        .       .            .           .
                6  |  -.2358423          .        .       .            .           .
                7  |  -.0814108          .        .       .            .           .
                8  |  -.0112969          .        .       .            .           .
                9  |   .0148766          .        .       .            .           .
               10  |   .0004639          .        .       .            .           .
               11  |  -.1254285          .        .       .            .           .
                   |
            n#wave |
             2  2  |  -.0643478          .        .       .            .           .
             2  3  |  -.0662678          .        .       .            .           .
             2  4  |  -.0578422          .        .       .            .           .
             2  5  |  -.0473652          .        .       .            .           .
             2  6  |  -.0853667          .        .       .            .           .
             2  7  |  -.0394312          .        .       .            .           .
             2  8  |  -.0708069          .        .       .            .           .
             2  9  |   -.075032          .        .       .            .           .
             2 10  |  -.3295891          .        .       .            .           .
             2 11  |  -.2095535          .        .       .            .           .
             3  2  |  -.0728997          .        .       .            .           .
             3  3  |  -.0518342          .        .       .            .           .
             3  4  |  -.0699845          .        .       .            .           .
             3  5  |  -.1106934          .        .       .            .           .
             3  6  |  -.1180719          .        .       .            .           .
             3  7  |  -.1301184          .        .       .            .           .
             3  8  |  -.0935258          .        .       .            .           .
             3  9  |  -.2324951          .        .       .            .           .
             3 10  |  -.1114713          .        .       .            .           .
             3 11  |  -.0940083          .        .       .            .           .
             4  2  |   -.106982          .        .       .            .           .
             4  3  |  -.0787109          .        .       .            .           .
             4  4  |  -.1283656          .        .       .            .           .
             4  5  |  -.1625773          .        .       .            .           .
             4  6  |  -.1873442          .        .       .            .           .
             4  7  |   -.117793          .        .       .            .           .
             4  8  |  -.2318431          .        .       .            .           .
             4  9  |  -.2551372          .        .       .            .           .
             4 10  |  -.3843694          .        .       .            .           .
             4 11  |  -.2649295          .        .       .            .           .
             5  2  |  -.0734095          .        .       .            .           .
             5  3  |  -.0234783          .        .       .            .           .
             5  4  |  -.0159155          .        .       .            .           .
             5  5  |  -.0559126          .        .       .            .           .
             5  6  |   -.101347          .        .       .            .           .
             5  7  |  -.0795556          .        .       .            .           .
             5  8  |  -.1140959          .        .       .            .           .
             5  9  |  -.2179668          .        .       .            .           .
             5 10  |  -.0974248          .        .       .            .           .
             5 11  |  -.1424405          .        .       .            .           .
             6  2  |  -.1010797          .        .       .            .           .
             6  3  |  -.0454846          .        .       .            .           .
             6  4  |  -.1003872          .        .       .            .           .
             6  5  |   -.088858          .        .       .            .           .
             6  6  |  -.1531087          .        .       .            .           .
             6  7  |  -.1132835          .        .       .            .           .
             6  8  |  -.2266002          .        .       .            .           .
             6  9  |  -.2277737          .        .       .            .           .
             6 10  |  -.3156583          .        .       .            .           .
             6 11  |  -.3018591          .        .       .            .           .
             7  2  |  -.0581012          .        .       .            .           .
             7  3  |  -.0417004          .        .       .            .           .
             7  4  |  -.0616403          .        .       .            .           .
             7  5  |  -.0719415          .        .       .            .           .
             7  6  |  -.1312024          .        .       .            .           .
             7  7  |  -.1468417          .        .       .            .           .
             7  8  |  -.1499965          .        .       .            .           .
             7  9  |  -.1967728          .        .       .            .           .
             7 10  |  -.0825648          .        .       .            .           .
             7 11  |  -.1068418          .        .       .            .           .
             8  2  |  -.0904973          .        .       .            .           .
             8  3  |  -.0521433          .        .       .            .           .
             8  4  |  -.1184543          .        .       .            .           .
             8  5  |  -.1648928          .        .       .            .           .
             8  6  |  -.1509678          .        .       .            .           .
             8  7  |  -.1594186          .        .       .            .           .
             8  8  |  -.2144339          .        .       .            .           .
             8  9  |  -.2578722          .        .       .            .           .
             8 10  |  -.3419673          .        .       .            .           .
             8 11  |   -.357708          .        .       .            .           .
             9  2  |  -.0117017          .        .       .            .           .
             9  3  |   -.027996          .        .       .            .           .
             9  4  |  -.0282918          .        .       .            .           .
             9  5  |  -.0638354          .        .       .            .           .
             9  6  |  -.0927401          .        .       .            .           .
             9  7  |  -.1580878          .        .       .            .           .
             9  8  |  -.1248834          .        .       .            .           .
             9  9  |  -.2308876          .        .       .            .           .
             9 10  |  -.1281028          .        .       .            .           .
             9 11  |  -.0627875          .        .       .            .           .
            10  2  |          0  (empty)
            10  3  |          0  (empty)
            10  4  |          0  (empty)
            10  5  |          0  (empty)
            10  6  |          0  (empty)
            10  7  |          0  (empty)
            10  8  |          0  (empty)
            10  9  |          0  (empty)
            10 10  |          0  (empty)
            10 11  |          0  (empty)
                   |
             _cons |   .2211984          .        .       .            .           .
      -------------+----------------------------------------------------------------
           sigma_u |  .05785425
           sigma_e |          .
               rho |          .   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      F test that all u_i=0: F(9, 0) = .                           Prob > F =      .
      In sum, your approach is neither feasible, nor methodologically sound.

      I would recommend you to take a look at any decent textbook on panel data econometrics and re-think your research strategy.

      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Dear Carlo,

        thanks a lot for you response. As said, I am pretty new on this kind of analysis, and sorry if I said something which does not make any sense.

        I'll go certainly through some text, do you have any suggestion in that sense?

        Anyway, when referring at fixed part I was referring at the dummy I included for each cohort (i.n) in the analysis, is that wrong?

        Thanks, G

        Comment


        • #5
          Giorgio:
          as far as readings are concerned, see Jeff Wooldridge 's textbook on panel data regression.
          Stata users often have https://www.stata.com/bookstore/micr...metrics-stata/ on their book shelves.
          Fixed part has a meaning in -mixed- model; you probably meant fixed effect.
          As an aside, if you thought that your query was worth posting, that's fine: no need to apologize.
          Once, Nick Cox posted (in an English only a bit better than mine ), that we are all beginners: some of us are only more experienced.
          I still think that Nick's sentence captured in full the core meaning of posting/contributing to this forum.
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment

          Working...
          X