Announcement

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

  • Efficient way to estimate cohort-specific event-study regression with many cohorts

    Hello everyone,

    I am estimating an event-study regression with a dependent variable y, an event-time indicator t_idx that takes values from 1 to 16, and a cohort variable. The goal is to estimate cohort-specific event-time effects, using the period where t_idx == 5 as the baseline within each cohort.

    In a smaller setting (with only a few cohorts), I implemented it as follows:

    Code:
    *define cohort
    local cohort languageregion
    local coh3 = substr("`cohort'", 1, 3)
    local coh9 = substr("`cohort'", 1, 9)
    
    *create interaction dummies
    xi i.t_idx*i.`cohort', noomit
    drop _It_iX`coh3'_5_* _It_idx* _I`coh9'_*
    
    * drop empty interactions
    local vardrop
    foreach var of varlist _I* {
        quietly summarize `var', meanonly
        if r(mean) == 0 {
            di "`var' --> delete"
            local vardrop `vardrop' `var'
        }
    }
    capture drop `vardrop'
    
    * regression
    reg y _It_iX`coh3'_* i.age i.statyear, r
    Now I would like to replace the cohort variable with municipality, which has more than 2,000 unique values. With this approach, Stata would have to generate roughly 15 × 2,000 = 30'000 interaction dummies, which is obviously not efficient.

    I was wondering if there is a more efficient way to estimate this event-study specification. For example i thought about using Stata’s factor-variable notation (# or ##), but I haven’t figured out how to replicate the structure above — specifically, how to ensure that t_idx == 5 serves as the baseline within each cohort.

    Any suggestions or references to more efficient approaches would be very welcome.

    Thank you for your time and help,
    Heike Waechter

  • #2
    Originally posted by Heike Waechter View Post
    I am estimating an event-study regression . . . with municipality, which has more than 2,000 unique values. . . . I was wondering if there is a more efficient way to estimate this event-study specification.
    No one's yet taken you up on this, and so I'll give it try: if efficiency is what you're after, then how about modeling municipality as a random effect?

    In mixed-effects linear regression models (mixed) and mixed-effects generalized linear regression models (meglm and other, more-specific, estimation commands), you can include time as a random slope, which is the same as a time × municipality interaction term. For individual municipality time slopes, you can examine the best linear unbiased estimates (BLUPs) after mixed and corresponding so-called empirical Bayes predictions after meglm using the postestimation command predict double . . . , reffects.

    As an aside, I don't recall seeing a linear model fitted to an event study's data. I assume that you've considered what's offered in
    Code:
    help st
    and have opted for regress despite what's shown there.

    Comment


    • #3
      First, thank you for your answer — it’s greatly appreciated.

      I may have overemphasized the efficiency aspect a bit in my initial post. I’m perfectly fine with a slower program; it’s just that my current version runs for days without making progress on the dummy creation. By efficiency I mainly meant computationally feasible — it doesn’t need to be lightning fast, just something that runs in hours rather than days. In that light, do you think it’s not possible to make the current approach work (for example by using Stata’s # or ## operators correctly)?

      I don’t know much about mixed-effects beyond what a quick search told me, but I’m worried that it’s not conceptually the same. If I understand correctly, the random-slope model gives an overall pattern plus deviations, rather than a separate coefficient for every municipality × event-time combination.

      Do I understand that right? And if so, is there a way to stay closer to the explicit interaction setup but still make it computationally feasible?

      Comment


      • #4
        Originally posted by Heike Waechter View Post
        I may have overemphasized the efficiency aspect a bit in my initial post. I’m perfectly fine with a slower program . . . By efficiency I mainly meant computationally feasible . . .
        I wasn't using the word efficiency in that sense; regardless, you might not get anything tractable with a fixed-effect interaction approach when one factor has more than two thousand levels.

        If I understand correctly, the random-slope model gives an overall pattern plus deviations, rather than a separate coefficient for every municipality × event-time combination.

        Do I understand that right?
        The random slopes are estimable individually, and so you can add them to the fixed-effect coefficient for time to get the municipality's overall prediction, which will be analogous to your separate coefficients, albeit likely with some so-called shrinkage.

        It seems that i misconstrued what you mean by "event-study", perhaps in a manner similar in another recent thread

        Comment


        • #5
          Originally posted by Heike Waechter View Post
          With this approach, Stata would have to generate roughly 15 × 2,000 = 30'000 interaction dummies
          What do you intend to do with this output? Can you really make sense of all 30,000 dummy coefficients?


          I was wondering if there is a more efficient way to estimate this event-study specification. For example i thought about using Stata’s factor-variable notation (# or ##), but I haven’t figured out how to replicate the structure above — specifically, how to ensure that t_idx == 5 serves as the baseline within each cohort.
          There is some efficiency to be gained by not manually creating the indicators, but I suspect the main issue is the number of parameters you want to estimate. OLS has to invert a matrix, so this brute-force approach of estimating all dummy variable coefficients is not recommended. You can also absorb the age and state-year dummies if their estimates are of no immediate interest. If you provide a reproducible example with only a few levels of the municipality/cohort variable, I can illustrate how to achieve what you want using factor-variable notation.

          Comment


          • #6
            Thank you both for your helpful input — and apologies for the delay over the weekend.

            My event-study is on measuring “child penalties”: in year t_idx=6 the child is born, and t_idx=5 serves as the baseline (i.e., income one year before the birth).

            What I plan to do with the estimates is to use a “movers design”. Therefore i will ultimately average the child-penalties within municipalities. Nevertheless, it remains of interest to me to observe the variance across municipalities for the different t_idx before averaging — and hence I would like to estimate all the municipality × event-time interactions. That also adds consistency with previous subgroup analyses I’ve done (by language region, degree of urbanisation etc.).

            That said, if estimating every municipality’s full interaction proves intractable, estimating the average effect may indeed be the best course of action. Would that be achieved by the random slope approach?

            A question for you, Andrew: when you refer to a “reproducible example”, could you clarify what exactly you need? Would it suffice for me to provide my full code (with anonymised/synthetic data) or do you need actual data?

            Thanks again, and I look forward to any suggestions you may have for feasibly estimating this many interactions (or moving to a pooled/random‐slope alternative).

            Comment


            • #7
              Originally posted by Heike Waechter View Post
              A question for you, Andrew: when you refer to a “reproducible example”, could you clarify what exactly you need? Would it suffice for me to provide my full code (with anonymised/synthetic data) or do you need actual data?
              Yes, e.g., data that can be used to run what you have in #2:

              *define cohort
              local cohort languageregion
              local coh3 = substr("`cohort'", 1, 3)
              local coh9 = substr("`cohort'", 1, 9)

              *create interaction dummies
              xi i.t_idx*i.`cohort', noomit
              drop _It_iX`coh3'_5_* _It_idx* _I`coh9'_*

              * drop empty interactions
              local vardrop
              foreach var of varlist _I* {
              quietly summarize `var', meanonly
              if r(mean) == 0 {
              di "`var' --> delete"
              local vardrop `vardrop' `var'
              }
              }
              capture drop `vardrop'

              * regression
              reg y _It_iX`coh3'_* i.age i.statyear, r


              Would that be achieved by the random slope approach?
              For observational data, it would be difficult to justify a random effects model. I would not consider this.


              Therefore i will ultimately average the child-penalties within municipalities. Nevertheless, it remains of interest to me to observe the variance across municipalities for the different t_idx before averaging — and hence I would like to estimate all the municipality × event-time interactions.
              The predicted residuals obtained after an FE transformation would provide the same information, so it would appear unnecessary to estimate all the interaction terms and then average them subsequently. There is some discussion here: https://www.statalist.org/forums/for...cts-with-xtreg. This could also be illustrated with a data example.

              Comment


              • #8
                Thank you for your willingness to take a look.

                I’ve prepared code that generates a synthetic dataset and runs an analysis replicating the structure of my actual setup — an event-study design with multiple municipalities (cohorts), an event-time index, age, calendar year, and an outcome variable.

                Code:
                // ===== Synthetic dataset for reproducible example =====
                clear  
                set seed 12345  
                
                // Parameters
                local municipality     = 100        // number of municipalities/cohorts
                local Npersons   = 50          // number of individuals per municipality
                local Tmin       = 1          // event-time baseline
                local Tmax       = 17        // event-time max
                local Tobs       = `Tmax' - `Tmin'
                local obs        = `municipality' * `Npersons' * `Tobs'
                display `obs'
                
                // Create panel: each municipality × each individual × each t_idx
                set obs `obs'
                
                // Define identifiers
                gen mun_id = ceil(_n / (`Npersons' * `Tobs'))
                gen person_in_unit = mod(ceil(_n / `Tobs') - 1, `Npersons') + 1
                gen id = mun_id * 10000 + person_in_unit   // individual identifier
                
                // Create t_idx
                bysort mun_id person_in_unit: gen t_idx = `Tmin' + _n - 1
                
                // Cohort variable (e.g., language region)
                gen str3 language = cond(mod(mun_id,3)==0, "GER", ///
                                      cond(mod(mun_id,3)==1, "FRE", "ITA"))
                
                // We first generate a random base statyear for each individual
                bysort id: gen statyear0 = 1995 + floor(runiform()*10)   // base year between 1995 and 2004
                // Then statyear for each row = statyear0 + t_idx
                gen statyear = statyear0 + t_idx
                
                // Age: define starting age at t_idx == 0, then age = start_age + t_idx
                bysort id: gen start_age = 25 + int(runiform()*20)   // starting age between ~25 and ~44 at t_idx = 0
                gen age = start_age + t_idx
                
                // Outcome y: municipality + individual + event time effects + noise
                gen u_intercept = rnormal(0, 5)
                gen u_slope     = rnormal(0, 0.5)
                gen event_effect = cond(t_idx>=0, -10 + 0.5*t_idx, 0)
                gen y = 100 + u_intercept + u_slope * t_idx + event_effect + rnormal(0, 10)
                
                // Clean up interim vars
                drop u_intercept u_slope start_age statyear0 event_effect
                
                label var id            "Individual identifier"
                label var mun_id       "Municipality / cohort id"
                label var person_in_unit "Person within municipality"
                label var cohort        "Cohort (language region, fictitious)"
                label var t_idx         "Event time index (years relative)"
                label var age           "Age of individual (synthetic)"
                label var statyear      "Calendar year of observation"
                label var y             "Outcome (synthetic)"
                
                * analysis
                
                *define cohort
                local cohort unit_id
                local coh3 = substr("`cohort'", 1, 3)
                local coh9 = substr("`cohort'", 1, 9)
                
                // Create interaction dummies as in your original code
                *create interaction dummies
                xi i.t_idx*i.`cohort', noomit
                drop _It_iX`coh3'_5_* _It_idx* _I`coh9'_*
                
                * drop empty interactions
                local vardrop
                foreach var of varlist _I* {
                    quietly summarize `var', meanonly
                    if r(mean) == 0 {
                        di "`var' --> delete"
                        local vardrop `vardrop' `var'
                    }
                }
                capture drop `vardrop'
                
                * regression
                reg y _It_iX`coh3'_* i.age i.statyear, r
                Is this sufficient for you to show me how to run with interactions aswell as predict residuals to get the averages directly? When talking about averaging the interaction terms it is important to note that i would only average over the post periods (t_idx from 6 to 16). I am not sure thats really captured in the post you linked where you (as far as i understand) recommend to run a regression like "reg y eventtime i.age i.year i.mun_id" and then extract the fe for the mun_ids, right?

                Thanks for helping me out and if you need any additional info, just let me know!
                Last edited by Heike Waechter; 03 Nov 2025, 09:35.

                Comment


                • #9
                  Originally posted by Heike Waechter View Post
                  I’ve prepared code that generates a synthetic dataset and runs an analysis replicating the structure of my actual setup — an event-study design with multiple municipalities (cohorts), an event-time index, age, calendar year, and an outcome variable.
                  Thanks. Please check the example again. When I run the code, I get the error:

                  Code:
                  . label var cohort        "Cohort (language region, fictitious)"
                  variable cohort not found
                  r(111);
                  I don't see that you have generated a variable named "cohort" anywhere.

                  Comment


                  • #10
                    ah sry, i chose to change the naming and forgot that one. here you go:

                    Code:
                    // ===== Synthetic dataset for reproducible example =====
                    clear  
                    set seed 12345  
                    
                    // Parameters
                    local municipality     = 100        // number of municipalities/cohorts
                    local Npersons   = 50          // number of individuals per municipality
                    local Tmin       = 1          // event-time baseline
                    local Tmax       = 17        // event-time max
                    local Tobs       = `Tmax' - `Tmin' 
                    local obs        = `municipality' * `Npersons' * `Tobs'
                    display `obs' 
                    
                    // Create panel: each municipality × each individual × each t_idx
                    set obs `obs'
                    
                    // Define identifiers
                    gen mun_id = ceil(_n / (`Npersons' * `Tobs'))
                    gen person_in_unit = mod(ceil(_n / `Tobs') - 1, `Npersons') + 1
                    gen id = mun_id * 10000 + person_in_unit   // individual identifier
                    
                    // Create t_idx
                    bysort mun_id person_in_unit: gen t_idx = `Tmin' + _n - 1
                    
                    // Cohort variable (e.g., language region)
                    gen str3 language = cond(mod(mun_id,3)==0, "GER", ///
                                          cond(mod(mun_id,3)==1, "FRE", "ITA"))
                    
                    // We first generate a random base statyear for each individual
                    bysort id: gen statyear0 = 1995 + floor(runiform()*10)   // base year between 1995 and 2004
                    // Then statyear for each row = statyear0 + t_idx
                    gen statyear = statyear0 + t_idx
                    
                    // Age: define starting age at t_idx == 0, then age = start_age + t_idx
                    bysort id: gen start_age = 25 + int(runiform()*20)   // starting age between ~25 and ~44 at t_idx = 0
                    gen age = start_age + t_idx
                    
                    // Outcome y: municipality + individual + event time effects + noise
                    gen u_intercept = rnormal(0, 5)
                    gen u_slope     = rnormal(0, 0.5)
                    gen event_effect = cond(t_idx>=0, -10 + 0.5*t_idx, 0)
                    gen y = 100 + u_intercept + u_slope * t_idx + event_effect + rnormal(0, 10)
                    
                    // Clean up interim vars
                    drop u_intercept u_slope start_age statyear0 event_effect
                    
                    label var id            "Individual identifier"
                    label var mun_id       "Municipality / cohort id"
                    label var person_in_unit "Person within municipality"
                    label var language        "language region"
                    label var t_idx         "Event time index (years relative)"
                    label var age           "Age of individual (synthetic)"
                    label var statyear      "Calendar year of observation"
                    label var y             "Outcome (synthetic)"
                    
                    * analysis
                    
                    *define cohort
                    local cohort language // choose mun_id or language
                    local coh3 = substr("`cohort'", 1, 3)
                    local coh9 = substr("`cohort'", 1, 9)
                    
                    // Create interaction dummies as in your original code
                    *create interaction dummies
                    xi i.t_idx*i.`cohort', noomit
                    drop _It_iX`coh3'_5_* _It_idx* _I`coh9'_*
                    
                    * drop empty interactions
                    local vardrop
                    foreach var of varlist _I* {
                        quietly summarize `var', meanonly
                        if r(mean) == 0 {
                            di "`var' --> delete"
                            local vardrop `vardrop' `var'
                        }
                    }
                    capture drop `vardrop'
                    
                    * regression
                    reg y _It_iX`coh3'_* i.age i.statyear, r

                    Comment


                    • #11
                      Thank you. This works. Here's how to run the regressions using factor variable notation. I'm teaching all day, so I'll post the solution that involves absorbing the interactions and then predicting the residuals later in the day.

                      Code:
                      // ===== Synthetic dataset for reproducible example =====
                      clear  
                      set seed 12345  
                      
                      // Parameters
                      local municipality     = 100        // number of municipalities/cohorts
                      local Npersons   = 50          // number of individuals per municipality
                      local Tmin       = 1          // event-time baseline
                      local Tmax       = 17        // event-time max
                      local Tobs       = `Tmax' - `Tmin' 
                      local obs        = `municipality' * `Npersons' * `Tobs'
                      display `obs' 
                      
                      // Create panel: each municipality × each individual × each t_idx
                      set obs `obs'
                      
                      // Define identifiers
                      gen mun_id = ceil(_n / (`Npersons' * `Tobs'))
                      gen person_in_unit = mod(ceil(_n / `Tobs') - 1, `Npersons') + 1
                      gen id = mun_id * 10000 + person_in_unit   // individual identifier
                      
                      // Create t_idx
                      bysort mun_id person_in_unit: gen t_idx = `Tmin' + _n - 1
                      
                      // Cohort variable (e.g., language region)
                      gen str3 language = cond(mod(mun_id,3)==0, "GER", ///
                                            cond(mod(mun_id,3)==1, "FRE", "ITA"))
                      
                      // We first generate a random base statyear for each individual
                      bysort id: gen statyear0 = 1995 + floor(runiform()*10)   // base year between 1995 and 2004
                      // Then statyear for each row = statyear0 + t_idx
                      gen statyear = statyear0 + t_idx
                      
                      // Age: define starting age at t_idx == 0, then age = start_age + t_idx
                      bysort id: gen start_age = 25 + int(runiform()*20)   // starting age between ~25 and ~44 at t_idx = 0
                      gen age = start_age + t_idx
                      
                      // Outcome y: municipality + individual + event time effects + noise
                      gen u_intercept = rnormal(0, 5)
                      gen u_slope     = rnormal(0, 0.5)
                      gen event_effect = cond(t_idx>=0, -10 + 0.5*t_idx, 0)
                      gen y = 100 + u_intercept + u_slope * t_idx + event_effect + rnormal(0, 10)
                      
                      // Clean up interim vars
                      drop u_intercept u_slope start_age statyear0 event_effect
                      
                      label var id            "Individual identifier"
                      label var mun_id       "Municipality / cohort id"
                      label var person_in_unit "Person within municipality"
                      label var language        "language region"
                      label var t_idx         "Event time index (years relative)"
                      label var age           "Age of individual (synthetic)"
                      label var statyear      "Calendar year of observation"
                      label var y             "Outcome (synthetic)"
                      
                      * analysis
                      
                      *define cohort
                      local cohort language // choose mun_id or language
                      local coh3 = substr("`cohort'", 1, 3)
                      local coh9 = substr("`cohort'", 1, 9)
                      
                      // Create interaction dummies as in your original code
                      *create interaction dummies
                      xi i.t_idx*i.`cohort', noomit
                      drop _It_iX`coh3'_5_* _It_idx* _I`coh9'_*
                      
                      * drop empty interactions
                      local vardrop
                      foreach var of varlist _I* {
                          quietly summarize `var', meanonly
                          if r(mean) == 0 {
                              di "`var' --> delete"
                              local vardrop `vardrop' `var'
                          }
                      }
                      capture drop `vardrop'
                      
                      * regression
                      reg y _It_iX`coh3'_* i.age i.statyear, r
                      
                      
                      egen lang= group(language)
                      
                      local omitted 
                      qui levelsof lang, local(levs)
                      foreach l of local levs{
                          local omitted `omitted' o5.t_idx#o.`l'.lang
                      }
                      
                      reg y ibn.t_idx#ibn.lang `omitted' i.age i.statyear, r noomit
                      Res.:

                      Code:
                      . * regression
                      . reg y _It_iX`coh3'_* i.age i.statyear, r
                      
                      Linear regression                               Number of obs     =     80,000
                                                                      F(103, 79896)     =      27.87
                                                                      Prob > F          =     0.0000
                                                                      R-squared         =     0.0348
                                                                      Root MSE          =     12.162
                      
                      --------------------------------------------------------------------------------
                                     |               Robust
                                   y | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      ---------------+----------------------------------------------------------------
                       _It_iXlan_1_1 |  -2.368133   .3336004    -7.10   0.000    -3.021988   -1.714278
                       _It_iXlan_1_2 |  -2.310124   .3433546    -6.73   0.000    -2.983097   -1.637151
                       _It_iXlan_1_3 |  -2.030665   .3387226    -6.00   0.000    -2.694559    -1.36677
                       _It_iXlan_2_1 |  -1.670071   .3224575    -5.18   0.000    -2.302085   -1.038056
                       _It_iXlan_2_2 |  -1.862749   .3324816    -5.60   0.000    -2.514411   -1.211087
                       _It_iXlan_2_3 |  -1.583652   .3354648    -4.72   0.000    -2.241161   -.9261431
                       _It_iXlan_3_1 |  -1.563066   .3132553    -4.99   0.000    -2.177044   -.9490873
                       _It_iXlan_3_2 |  -1.576734   .3279649    -4.81   0.000    -2.219543   -.9339246
                       _It_iXlan_3_3 |  -1.193576   .3323675    -3.59   0.000    -1.845014   -.5421378
                       _It_iXlan_4_1 |  -.7413887   .3187269    -2.33   0.020    -1.366091   -.1166859
                       _It_iXlan_4_2 |  -.4857789   .3178338    -1.53   0.126    -1.108731    .1371733
                       _It_iXlan_4_3 |  -.6801947   .3245295    -2.10   0.036     -1.31627   -.0441189
                       _It_iXlan_6_1 |   .4780968   .3246934     1.47   0.141    -.1583003    1.114494
                       _It_iXlan_6_2 |   .6149669    .331429     1.86   0.064    -.0346318    1.264566
                       _It_iXlan_6_3 |   .2160518   .3288104     0.66   0.511    -.4284144     .860518
                       _It_iXlan_7_1 |   1.535011   .3354032     4.58   0.000     .8776232      2.1924
                       _It_iXlan_7_2 |   .9206809   .3432816     2.68   0.007     .2478512    1.593511
                       _It_iXlan_7_3 |    .952353   .3310848     2.88   0.004     .3034288    1.601277
                       _It_iXlan_8_1 |   .7677342   .3368691     2.28   0.023     .1074729    1.427995
                       _It_iXlan_8_2 |   .7492054   .3397146     2.21   0.027      .083367    1.415044
                       _It_iXlan_8_3 |    1.19948   .3471386     3.46   0.001     .5190909     1.87987
                       _It_iXlan_9_1 |   1.656851   .3458675     4.79   0.000     .9789526    2.334749
                       _It_iXlan_9_2 |   2.412133   .3466938     6.96   0.000     1.732615    3.091651
                       _It_iXlan_9_3 |   1.538266   .3481109     4.42   0.000     .8559711    2.220561
                      _It_iXlan_10_1 |   1.955685   .3525141     5.55   0.000      1.26476    2.646611
                      _It_iXlan_10_2 |   2.651968   .3606623     7.35   0.000     1.945072    3.358864
                      _It_iXlan_10_3 |    2.01723     .36384     5.54   0.000     1.304106    2.730354
                      _It_iXlan_11_1 |   2.862153   .3619068     7.91   0.000     2.152817    3.571488
                      _It_iXlan_11_2 |   3.034875   .3701407     8.20   0.000     2.309402    3.760348
                      _It_iXlan_11_3 |   3.112749    .372354     8.36   0.000     2.382937     3.84256
                      _It_iXlan_12_1 |   3.044052   .3783696     8.05   0.000      2.30245    3.785654
                      _It_iXlan_12_2 |   3.347627   .3806228     8.80   0.000     2.601609    4.093646
                      _It_iXlan_12_3 |   3.188872   .3817797     8.35   0.000     2.440587    3.937158
                      _It_iXlan_13_1 |   3.966754   .3872396    10.24   0.000     3.207767    4.725741
                      _It_iXlan_13_2 |   3.903928   .3943237     9.90   0.000     3.131056      4.6768
                      _It_iXlan_13_3 |   3.539779   .3922857     9.02   0.000     2.770901    4.308656
                      _It_iXlan_14_1 |   4.276604   .4006579    10.67   0.000     3.491317    5.061891
                      _It_iXlan_14_2 |   4.516788   .4068208    11.10   0.000     3.719422    5.314154
                      _It_iXlan_14_3 |    4.23396    .405333    10.45   0.000      3.43951     5.02841
                      _It_iXlan_15_1 |   5.216766   .4113119    12.68   0.000     4.410597    6.022935
                      _It_iXlan_15_2 |   4.904253   .4078983    12.02   0.000     4.104775    5.703731
                      _It_iXlan_15_3 |   5.309786    .419863    12.65   0.000     4.486857    6.132715
                      _It_iXlan_16_1 |   4.722023    .427838    11.04   0.000     3.883463    5.560583
                      _It_iXlan_16_2 |   5.363941   .4285051    12.52   0.000     4.524074    6.203809
                      _It_iXlan_16_3 |   5.330657   .4290629    12.42   0.000     4.489697    6.171618
                                     |
                                 age |
                                 27  |   .7325874   .9076534     0.81   0.420    -1.046408    2.511582
                                 28  |   .3208175   .8504925     0.38   0.706    -1.346142    1.987778
                                 29  |    .191439   .8339289     0.23   0.818    -1.443056    1.825934
                                 30  |  -.4719228   .8236589    -0.57   0.567    -2.086289    1.142444
                                 31  |   -.142288   .8137081    -0.17   0.861    -1.737151    1.452575
                                 32  |   .1990107   .8054323     0.25   0.805    -1.379632    1.777653
                                 33  |  -.2738529   .7992741    -0.34   0.732    -1.840425    1.292719
                                 34  |  -.1529101   .7961833    -0.19   0.848    -1.713424    1.407604
                                 35  |  -.1288967    .793197    -0.16   0.871    -1.683558    1.425764
                                 36  |   .0588335   .7908345     0.07   0.941    -1.491197    1.608864
                                 37  |   .3921179   .7880807     0.50   0.619    -1.152515    1.936751
                                 38  |   .0813392   .7881708     0.10   0.918    -1.463471    1.626149
                                 39  |  -.1347576   .7870812    -0.17   0.864    -1.677432    1.407917
                                 40  |  -.4748054   .7847014    -0.61   0.545    -2.012815    1.063205
                                 41  |  -.0754757   .7830682    -0.10   0.923    -1.610284    1.459333
                                 42  |   .2493342   .7840692     0.32   0.750    -1.287437    1.786105
                                 43  |  -.1051961   .7849101    -0.13   0.893    -1.643615    1.433223
                                 44  |  -.1332997   .7836731    -0.17   0.865    -1.669294    1.402695
                                 45  |  -.0336313   .7837356    -0.04   0.966    -1.569748    1.502485
                                 46  |   -.077499   .7880767    -0.10   0.922    -1.622124    1.467126
                                 47  |  -.1240083   .7906083    -0.16   0.875    -1.673596    1.425579
                                 48  |  -.1406644   .7925696    -0.18   0.859    -1.694096    1.412767
                                 49  |   -.311831   .7964584    -0.39   0.695    -1.872884    1.249222
                                 50  |   .0795048   .8018629     0.10   0.921    -1.492141    1.651151
                                 51  |    -.03987   .8063175    -0.05   0.961    -1.620247    1.540507
                                 52  |    .175123   .8123457     0.22   0.829    -1.417069    1.767315
                                 53  |  -.2160892   .8206156    -0.26   0.792    -1.824491    1.392312
                                 54  |   .1508225   .8302669     0.18   0.856    -1.476495     1.77814
                                 55  |  -.1588468   .8413972    -0.19   0.850     -1.80798    1.490286
                                 56  |  -.4077025   .8533693    -0.48   0.633    -2.080301    1.264896
                                 57  |   .1506475   .8806643     0.17   0.864    -1.575449    1.876744
                                 58  |  -.5995126   .9128689    -0.66   0.511     -2.38873    1.189705
                                 59  |    .000663   .9649573     0.00   0.999    -1.890647    1.891973
                                 60  |   .1268308   1.179696     0.11   0.914    -2.185366    2.439027
                                     |
                            statyear |
                               1997  |   .6893219   .6308627     1.09   0.275     -.547165    1.925809
                               1998  |   .2284195   .5983482     0.38   0.703    -.9443392    1.401178
                               1999  |   .1217415    .578479     0.21   0.833    -1.012074    1.255557
                               2000  |  -.2051283   .5716441    -0.36   0.720    -1.325547    .9152904
                               2001  |   .1752776   .5685706     0.31   0.758    -.9391171    1.289672
                               2002  |   .3832778   .5644336     0.68   0.497    -.7230086    1.489564
                               2003  |    .053925   .5606968     0.10   0.923    -1.045037    1.152887
                               2004  |   .4116798   .5586755     0.74   0.461    -.6833205     1.50668
                               2005  |   .0171829   .5558482     0.03   0.975    -1.072276    1.106642
                               2006  |  -.2911823    .565337    -0.52   0.607    -1.399239    .8168745
                               2007  |   .0164182   .5695602     0.03   0.977    -1.099916    1.132753
                               2008  |   .0714586   .5724327     0.12   0.901    -1.050506    1.193423
                               2009  |  -.1116666   .5763015    -0.19   0.846    -1.241214    1.017881
                               2010  |   .0422877   .5792369     0.07   0.942    -1.093013    1.177588
                               2011  |   .2263829   .5824522     0.39   0.698    -.9152197    1.367985
                               2012  |   .2443245   .5900713     0.41   0.679    -.9122116    1.400861
                               2013  |   .3853788   .5961326     0.65   0.518    -.7830373    1.553795
                               2014  |  -.0020605   .6056642    -0.00   0.997    -1.189159    1.185038
                               2015  |   .0453184   .6138172     0.07   0.941    -1.157759    1.248396
                               2016  |  -.0543527   .6290408    -0.09   0.931    -1.287269    1.178563
                               2017  |   .2243876   .6525029     0.34   0.731    -1.054514    1.503289
                               2018  |  -.6865201    .677269    -1.01   0.311    -2.013963     .640923
                               2019  |  -.5075994   .7313385    -0.69   0.488    -1.941018    .9258194
                               2020  |   .3835909   .8298596     0.46   0.644    -1.242929     2.01011
                                     |
                               _cons |   92.67639   .9388149    98.72   0.000     90.83632    94.51646
                      --------------------------------------------------------------------------------
                      
                      . 
                      . 
                      . egen lang= group(language)
                      
                      . 
                      . local omitted 
                      
                      . qui levelsof lang, local(levs)
                      
                      . foreach l of local levs{
                        2.     local omitted `omitted' o5.t_idx#o.`l'.lang
                        3. }
                      
                      . 
                      . reg y ibn.t_idx#ibn.lang `omitted' i.age i.statyear, r noomit
                      
                      Linear regression                               Number of obs     =     80,000
                                                                      F(103, 79896)     =      27.87
                                                                      Prob > F          =     0.0000
                                                                      R-squared         =     0.0348
                                                                      Root MSE          =     12.162
                      
                      ------------------------------------------------------------------------------
                                   |               Robust
                                 y | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                        t_idx#lang |
                              1 1  |  -2.368133   .3336004    -7.10   0.000    -3.021988   -1.714278
                              1 2  |  -2.310124   .3433546    -6.73   0.000    -2.983097   -1.637151
                              1 3  |  -2.030665   .3387226    -6.00   0.000    -2.694559    -1.36677
                              2 1  |  -1.670071   .3224575    -5.18   0.000    -2.302085   -1.038056
                              2 2  |  -1.862749   .3324816    -5.60   0.000    -2.514411   -1.211087
                              2 3  |  -1.583652   .3354648    -4.72   0.000    -2.241161   -.9261431
                              3 1  |  -1.563066   .3132553    -4.99   0.000    -2.177044   -.9490873
                              3 2  |  -1.576734   .3279649    -4.81   0.000    -2.219543   -.9339246
                              3 3  |  -1.193576   .3323675    -3.59   0.000    -1.845014   -.5421378
                              4 1  |  -.7413887   .3187269    -2.33   0.020    -1.366091   -.1166859
                              4 2  |  -.4857789   .3178338    -1.53   0.126    -1.108731    .1371733
                              4 3  |  -.6801947   .3245295    -2.10   0.036     -1.31627   -.0441189
                              6 1  |   .4780968   .3246934     1.47   0.141    -.1583003    1.114494
                              6 2  |   .6149669    .331429     1.86   0.064    -.0346318    1.264566
                              6 3  |   .2160518   .3288104     0.66   0.511    -.4284144     .860518
                              7 1  |   1.535011   .3354032     4.58   0.000     .8776232      2.1924
                              7 2  |   .9206809   .3432816     2.68   0.007     .2478512    1.593511
                              7 3  |    .952353   .3310848     2.88   0.004     .3034288    1.601277
                              8 1  |   .7677342   .3368691     2.28   0.023     .1074729    1.427995
                              8 2  |   .7492054   .3397146     2.21   0.027      .083367    1.415044
                              8 3  |    1.19948   .3471386     3.46   0.001     .5190909     1.87987
                              9 1  |   1.656851   .3458675     4.79   0.000     .9789526    2.334749
                              9 2  |   2.412133   .3466938     6.96   0.000     1.732615    3.091651
                              9 3  |   1.538266   .3481109     4.42   0.000     .8559711    2.220561
                             10 1  |   1.955685   .3525141     5.55   0.000      1.26476    2.646611
                             10 2  |   2.651968   .3606623     7.35   0.000     1.945072    3.358864
                             10 3  |    2.01723     .36384     5.54   0.000     1.304106    2.730354
                             11 1  |   2.862153   .3619068     7.91   0.000     2.152817    3.571488
                             11 2  |   3.034875   .3701407     8.20   0.000     2.309402    3.760348
                             11 3  |   3.112749    .372354     8.36   0.000     2.382937     3.84256
                             12 1  |   3.044052   .3783696     8.05   0.000      2.30245    3.785654
                             12 2  |   3.347627   .3806228     8.80   0.000     2.601609    4.093646
                             12 3  |   3.188872   .3817797     8.35   0.000     2.440587    3.937158
                             13 1  |   3.966754   .3872396    10.24   0.000     3.207767    4.725741
                             13 2  |   3.903928   .3943237     9.90   0.000     3.131056      4.6768
                             13 3  |   3.539779   .3922857     9.02   0.000     2.770901    4.308656
                             14 1  |   4.276604   .4006579    10.67   0.000     3.491317    5.061891
                             14 2  |   4.516788   .4068208    11.10   0.000     3.719422    5.314154
                             14 3  |    4.23396    .405333    10.45   0.000      3.43951     5.02841
                             15 1  |   5.216766   .4113119    12.68   0.000     4.410597    6.022935
                             15 2  |   4.904253   .4078983    12.02   0.000     4.104775    5.703731
                             15 3  |   5.309786    .419863    12.65   0.000     4.486857    6.132715
                             16 1  |   4.722023    .427838    11.04   0.000     3.883463    5.560583
                             16 2  |   5.363941   .4285051    12.52   0.000     4.524074    6.203809
                             16 3  |   5.330657   .4290629    12.42   0.000     4.489697    6.171618
                                   |
                               age |
                               27  |   .7325874   .9076534     0.81   0.420    -1.046408    2.511582
                               28  |   .3208175   .8504925     0.38   0.706    -1.346142    1.987778
                               29  |    .191439   .8339289     0.23   0.818    -1.443056    1.825934
                               30  |  -.4719228   .8236589    -0.57   0.567    -2.086289    1.142444
                               31  |   -.142288   .8137081    -0.17   0.861    -1.737151    1.452575
                               32  |   .1990107   .8054323     0.25   0.805    -1.379632    1.777653
                               33  |  -.2738529   .7992741    -0.34   0.732    -1.840425    1.292719
                               34  |  -.1529101   .7961833    -0.19   0.848    -1.713424    1.407604
                               35  |  -.1288967    .793197    -0.16   0.871    -1.683558    1.425764
                               36  |   .0588335   .7908345     0.07   0.941    -1.491197    1.608864
                               37  |   .3921179   .7880807     0.50   0.619    -1.152515    1.936751
                               38  |   .0813392   .7881708     0.10   0.918    -1.463471    1.626149
                               39  |  -.1347576   .7870812    -0.17   0.864    -1.677432    1.407917
                               40  |  -.4748054   .7847014    -0.61   0.545    -2.012815    1.063205
                               41  |  -.0754757   .7830682    -0.10   0.923    -1.610284    1.459333
                               42  |   .2493342   .7840692     0.32   0.750    -1.287437    1.786105
                               43  |  -.1051961   .7849101    -0.13   0.893    -1.643615    1.433223
                               44  |  -.1332997   .7836731    -0.17   0.865    -1.669294    1.402695
                               45  |  -.0336313   .7837356    -0.04   0.966    -1.569748    1.502485
                               46  |   -.077499   .7880767    -0.10   0.922    -1.622124    1.467126
                               47  |  -.1240083   .7906083    -0.16   0.875    -1.673596    1.425579
                               48  |  -.1406644   .7925696    -0.18   0.859    -1.694096    1.412767
                               49  |   -.311831   .7964584    -0.39   0.695    -1.872884    1.249222
                               50  |   .0795048   .8018629     0.10   0.921    -1.492141    1.651151
                               51  |    -.03987   .8063175    -0.05   0.961    -1.620247    1.540507
                               52  |    .175123   .8123457     0.22   0.829    -1.417069    1.767315
                               53  |  -.2160892   .8206156    -0.26   0.792    -1.824491    1.392312
                               54  |   .1508225   .8302669     0.18   0.856    -1.476495     1.77814
                               55  |  -.1588468   .8413972    -0.19   0.850     -1.80798    1.490286
                               56  |  -.4077025   .8533693    -0.48   0.633    -2.080301    1.264896
                               57  |   .1506475   .8806643     0.17   0.864    -1.575449    1.876744
                               58  |  -.5995126   .9128689    -0.66   0.511     -2.38873    1.189705
                               59  |    .000663   .9649573     0.00   0.999    -1.890647    1.891973
                               60  |   .1268308   1.179696     0.11   0.914    -2.185366    2.439027
                                   |
                          statyear |
                             1997  |   .6893219   .6308627     1.09   0.275     -.547165    1.925809
                             1998  |   .2284195   .5983482     0.38   0.703    -.9443392    1.401178
                             1999  |   .1217415    .578479     0.21   0.833    -1.012074    1.255557
                             2000  |  -.2051283   .5716441    -0.36   0.720    -1.325547    .9152904
                             2001  |   .1752776   .5685706     0.31   0.758    -.9391171    1.289672
                             2002  |   .3832778   .5644336     0.68   0.497    -.7230086    1.489564
                             2003  |    .053925   .5606968     0.10   0.923    -1.045037    1.152887
                             2004  |   .4116798   .5586755     0.74   0.461    -.6833205     1.50668
                             2005  |   .0171829   .5558482     0.03   0.975    -1.072276    1.106642
                             2006  |  -.2911823    .565337    -0.52   0.607    -1.399239    .8168745
                             2007  |   .0164182   .5695602     0.03   0.977    -1.099916    1.132753
                             2008  |   .0714586   .5724327     0.12   0.901    -1.050506    1.193423
                             2009  |  -.1116666   .5763015    -0.19   0.846    -1.241214    1.017881
                             2010  |   .0422877   .5792369     0.07   0.942    -1.093013    1.177588
                             2011  |   .2263829   .5824522     0.39   0.698    -.9152197    1.367985
                             2012  |   .2443245   .5900713     0.41   0.679    -.9122116    1.400861
                             2013  |   .3853788   .5961326     0.65   0.518    -.7830373    1.553795
                             2014  |  -.0020605   .6056642    -0.00   0.997    -1.189159    1.185038
                             2015  |   .0453184   .6138172     0.07   0.941    -1.157759    1.248396
                             2016  |  -.0543527   .6290408    -0.09   0.931    -1.287269    1.178563
                             2017  |   .2243876   .6525029     0.34   0.731    -1.054514    1.503289
                             2018  |  -.6865201    .677269    -1.01   0.311    -2.013963     .640923
                             2019  |  -.5075994   .7313385    -0.69   0.488    -1.941018    .9258194
                             2020  |   .3835909   .8298596     0.46   0.644    -1.242929     2.01011
                                   |
                             _cons |   92.67639   .9388149    98.72   0.000     90.83632    94.51646
                      ------------------------------------------------------------------------------

                      Comment


                      • #12
                        Here is a way to recover the dummy coefficients from the predicted fixed effects. At present, the official estimators do not allow you to absorb interactions, but reghdfe from https://github.com/sergiocorreia/reghdfe does.

                        Code:
                        // ===== Synthetic dataset for reproducible example =====
                        clear  
                        set seed 12345  
                        
                        // Parameters
                        local municipality     = 100        // number of municipalities/cohorts
                        local Npersons   = 50          // number of individuals per municipality
                        local Tmin       = 1          // event-time baseline
                        local Tmax       = 17        // event-time max
                        local Tobs       = `Tmax' - `Tmin' 
                        local obs        = `municipality' * `Npersons' * `Tobs'
                        display `obs' 
                        
                        // Create panel: each municipality × each individual × each t_idx
                        set obs `obs'
                        
                        // Define identifiers
                        gen mun_id = ceil(_n / (`Npersons' * `Tobs'))
                        gen person_in_unit = mod(ceil(_n / `Tobs') - 1, `Npersons') + 1
                        gen id = mun_id * 10000 + person_in_unit   // individual identifier
                        
                        // Create t_idx
                        bysort mun_id person_in_unit: gen t_idx = `Tmin' + _n - 1
                        
                        // Cohort variable (e.g., language region)
                        gen str3 language = cond(mod(mun_id,3)==0, "GER", ///
                                              cond(mod(mun_id,3)==1, "FRE", "ITA"))
                        
                        // We first generate a random base statyear for each individual
                        bysort id: gen statyear0 = 1995 + floor(runiform()*10)   // base year between 1995 and 2004
                        // Then statyear for each row = statyear0 + t_idx
                        gen statyear = statyear0 + t_idx
                        
                        // Age: define starting age at t_idx == 0, then age = start_age + t_idx
                        bysort id: gen start_age = 25 + int(runiform()*20)   // starting age between ~25 and ~44 at t_idx = 0
                        gen age = start_age + t_idx
                        
                        // Outcome y: municipality + individual + event time effects + noise
                        gen u_intercept = rnormal(0, 5)
                        gen u_slope     = rnormal(0, 0.5)
                        gen event_effect = cond(t_idx>=0, -10 + 0.5*t_idx, 0)
                        gen y = 100 + u_intercept + u_slope * t_idx + event_effect + rnormal(0, 10)
                        
                        // Clean up interim vars
                        drop u_intercept u_slope start_age statyear0 event_effect
                        
                        label var id            "Individual identifier"
                        label var mun_id       "Municipality / cohort id"
                        label var person_in_unit "Person within municipality"
                        label var language        "language region"
                        label var t_idx         "Event time index (years relative)"
                        label var age           "Age of individual (synthetic)"
                        label var statyear      "Calendar year of observation"
                        label var y             "Outcome (synthetic)"
                        
                        * analysis
                        
                        
                        egen lang= group(language)
                        
                        local omitted 
                        qui levelsof lang, local(levs)
                        foreach l of local levs{
                            local omitted `omitted' o5.t_idx#o.`l'.lang
                        }
                        
                        reg y ibn.t_idx#ibn.lang `omitted' i.age i.statyear, r noomit 
                        
                        qui reghdfe y i.age i.statyear, absorb(i.t_idx#i.lang, savefe)  vce(robust)
                        egen mean_t5= mean(cond(t_idx==5, __hdfe1__, .))
                        egen base= max(cond(t_idx==5, mean_t5, .))
                        gen coef= __hdfe1__- base 
                        table (t_idx lang), statistic(mean coef) nototal
                        Res.: (Selection highlighted)

                        Code:
                        . reg y ibn.t_idx#ibn.lang `omitted' i.age i.statyear, r noomit 
                        
                        Linear regression                               Number of obs     =     80,000
                                                                        F(103, 79896)     =      27.87
                                                                        Prob > F          =     0.0000
                                                                        R-squared         =     0.0348
                                                                        Root MSE          =     12.162
                        
                        ------------------------------------------------------------------------------
                                     |               Robust
                                   y | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                        -------------+----------------------------------------------------------------
                          t_idx#lang |
                                1 1  |  -2.368133   .3336004    -7.10   0.000    -3.021988   -1.714278
                                1 2  |  -2.310124   .3433546    -6.73   0.000    -2.983097   -1.637151
                                1 3  |  -2.030665   .3387226    -6.00   0.000    -2.694559    -1.36677
                                2 1  |  -1.670071   .3224575    -5.18   0.000    -2.302085   -1.038056
                                2 2  |  -1.862749   .3324816    -5.60   0.000    -2.514411   -1.211087
                                2 3  |  -1.583652   .3354648    -4.72   0.000    -2.241161   -.9261431
                                3 1  |  -1.563066   .3132553    -4.99   0.000    -2.177044   -.9490873
                                3 2  |  -1.576734   .3279649    -4.81   0.000    -2.219543   -.9339246
                                3 3  |  -1.193576   .3323675    -3.59   0.000    -1.845014   -.5421378
                                4 1  |  -.7413887   .3187269    -2.33   0.020    -1.366091   -.1166859
                                4 2  |  -.4857789   .3178338    -1.53   0.126    -1.108731    .1371733
                                4 3  |  -.6801947   .3245295    -2.10   0.036     -1.31627   -.0441189
                                6 1  |   .4780968   .3246934     1.47   0.141    -.1583003    1.114494
                                6 2  |   .6149669    .331429     1.86   0.064    -.0346318    1.264566
                                6 3  |   .2160518   .3288104     0.66   0.511    -.4284144     .860518
                                7 1  |   1.535011   .3354032     4.58   0.000     .8776232      2.1924
                                7 2  |   .9206809   .3432816     2.68   0.007     .2478512    1.593511
                                7 3  |    .952353   .3310848     2.88   0.004     .3034288    1.601277
                                8 1  |   .7677342   .3368691     2.28   0.023     .1074729    1.427995
                                8 2  |   .7492054   .3397146     2.21   0.027      .083367    1.415044
                                8 3  |    1.19948   .3471386     3.46   0.001     .5190909     1.87987
                                9 1  |   1.656851   .3458675     4.79   0.000     .9789526    2.334749
                                9 2  |   2.412133   .3466938     6.96   0.000     1.732615    3.091651
                                9 3  |   1.538266   .3481109     4.42   0.000     .8559711    2.220561
                               10 1  |   1.955685   .3525141     5.55   0.000      1.26476    2.646611
                               10 2  |   2.651968   .3606623     7.35   0.000     1.945072    3.358864
                               10 3  |    2.01723     .36384     5.54   0.000     1.304106    2.730354
                               11 1  |   2.862153   .3619068     7.91   0.000     2.152817    3.571488
                               11 2  |   3.034875   .3701407     8.20   0.000     2.309402    3.760348
                               11 3  |   3.112749    .372354     8.36   0.000     2.382937     3.84256
                               12 1  |   3.044052   .3783696     8.05   0.000      2.30245    3.785654
                               12 2  |   3.347627   .3806228     8.80   0.000     2.601609    4.093646
                               12 3  |   3.188872   .3817797     8.35   0.000     2.440587    3.937158
                               13 1  |   3.966754   .3872396    10.24   0.000     3.207767    4.725741
                               13 2  |   3.903928   .3943237     9.90   0.000     3.131056      4.6768
                               13 3  |   3.539779   .3922857     9.02   0.000     2.770901    4.308656
                               14 1  |   4.276604   .4006579    10.67   0.000     3.491317    5.061891
                               14 2  |   4.516788   .4068208    11.10   0.000     3.719422    5.314154
                               14 3  |    4.23396    .405333    10.45   0.000      3.43951     5.02841
                               15 1  |   5.216766   .4113119    12.68   0.000     4.410597    6.022935
                               15 2  |   4.904253   .4078983    12.02   0.000     4.104775    5.703731
                               15 3  |   5.309786    .419863    12.65   0.000     4.486857    6.132715
                               16 1  |   4.722023    .427838    11.04   0.000     3.883463    5.560583
                               16 2  |   5.363941   .4285051    12.52   0.000     4.524074    6.203809
                               16 3  |   5.330657   .4290629    12.42   0.000     4.489697    6.171618
                                     |
                                 age |
                                 27  |   .7325874   .9076534     0.81   0.420    -1.046408    2.511582
                                 28  |   .3208175   .8504925     0.38   0.706    -1.346142    1.987778
                                 29  |    .191439   .8339289     0.23   0.818    -1.443056    1.825934
                                 30  |  -.4719228   .8236589    -0.57   0.567    -2.086289    1.142444
                                 31  |   -.142288   .8137081    -0.17   0.861    -1.737151    1.452575
                                 32  |   .1990107   .8054323     0.25   0.805    -1.379632    1.777653
                                 33  |  -.2738529   .7992741    -0.34   0.732    -1.840425    1.292719
                                 34  |  -.1529101   .7961833    -0.19   0.848    -1.713424    1.407604
                                 35  |  -.1288967    .793197    -0.16   0.871    -1.683558    1.425764
                                 36  |   .0588335   .7908345     0.07   0.941    -1.491197    1.608864
                                 37  |   .3921179   .7880807     0.50   0.619    -1.152515    1.936751
                                 38  |   .0813392   .7881708     0.10   0.918    -1.463471    1.626149
                                 39  |  -.1347576   .7870812    -0.17   0.864    -1.677432    1.407917
                                 40  |  -.4748054   .7847014    -0.61   0.545    -2.012815    1.063205
                                 41  |  -.0754757   .7830682    -0.10   0.923    -1.610284    1.459333
                                 42  |   .2493342   .7840692     0.32   0.750    -1.287437    1.786105
                                 43  |  -.1051961   .7849101    -0.13   0.893    -1.643615    1.433223
                                 44  |  -.1332997   .7836731    -0.17   0.865    -1.669294    1.402695
                                 45  |  -.0336313   .7837356    -0.04   0.966    -1.569748    1.502485
                                 46  |   -.077499   .7880767    -0.10   0.922    -1.622124    1.467126
                                 47  |  -.1240083   .7906083    -0.16   0.875    -1.673596    1.425579
                                 48  |  -.1406644   .7925696    -0.18   0.859    -1.694096    1.412767
                                 49  |   -.311831   .7964584    -0.39   0.695    -1.872884    1.249222
                                 50  |   .0795048   .8018629     0.10   0.921    -1.492141    1.651151
                                 51  |    -.03987   .8063175    -0.05   0.961    -1.620247    1.540507
                                 52  |    .175123   .8123457     0.22   0.829    -1.417069    1.767315
                                 53  |  -.2160892   .8206156    -0.26   0.792    -1.824491    1.392312
                                 54  |   .1508225   .8302669     0.18   0.856    -1.476495     1.77814
                                 55  |  -.1588468   .8413972    -0.19   0.850     -1.80798    1.490286
                                 56  |  -.4077025   .8533693    -0.48   0.633    -2.080301    1.264896
                                 57  |   .1506475   .8806643     0.17   0.864    -1.575449    1.876744
                                 58  |  -.5995126   .9128689    -0.66   0.511     -2.38873    1.189705
                                 59  |    .000663   .9649573     0.00   0.999    -1.890647    1.891973
                                 60  |   .1268308   1.179696     0.11   0.914    -2.185366    2.439027
                                     |
                            statyear |
                               1997  |   .6893219   .6308627     1.09   0.275     -.547165    1.925809
                               1998  |   .2284195   .5983482     0.38   0.703    -.9443392    1.401178
                               1999  |   .1217415    .578479     0.21   0.833    -1.012074    1.255557
                               2000  |  -.2051283   .5716441    -0.36   0.720    -1.325547    .9152904
                               2001  |   .1752776   .5685706     0.31   0.758    -.9391171    1.289672
                               2002  |   .3832778   .5644336     0.68   0.497    -.7230086    1.489564
                               2003  |    .053925   .5606968     0.10   0.923    -1.045037    1.152887
                               2004  |   .4116798   .5586755     0.74   0.461    -.6833205     1.50668
                               2005  |   .0171829   .5558482     0.03   0.975    -1.072276    1.106642
                               2006  |  -.2911823    .565337    -0.52   0.607    -1.399239    .8168745
                               2007  |   .0164182   .5695602     0.03   0.977    -1.099916    1.132753
                               2008  |   .0714586   .5724327     0.12   0.901    -1.050506    1.193423
                               2009  |  -.1116666   .5763015    -0.19   0.846    -1.241214    1.017881
                               2010  |   .0422877   .5792369     0.07   0.942    -1.093013    1.177588
                               2011  |   .2263829   .5824522     0.39   0.698    -.9152197    1.367985
                               2012  |   .2443245   .5900713     0.41   0.679    -.9122116    1.400861
                               2013  |   .3853788   .5961326     0.65   0.518    -.7830373    1.553795
                               2014  |  -.0020605   .6056642    -0.00   0.997    -1.189159    1.185038
                               2015  |   .0453184   .6138172     0.07   0.941    -1.157759    1.248396
                               2016  |  -.0543527   .6290408    -0.09   0.931    -1.287269    1.178563
                               2017  |   .2243876   .6525029     0.34   0.731    -1.054514    1.503289
                               2018  |  -.6865201    .677269    -1.01   0.311    -2.013963     .640923
                               2019  |  -.5075994   .7313385    -0.69   0.488    -1.941018    .9258194
                               2020  |   .3835909   .8298596     0.46   0.644    -1.242929     2.01011
                                     |
                               _cons |   92.67639   .9388149    98.72   0.000     90.83632    94.51646
                        ------------------------------------------------------------------------------
                        
                        . 
                        . qui reghdfe y i.age i.statyear, absorb(i.t_idx#i.lang, savefe)  vce(robust)
                        
                        . egen mean_t5= mean(cond(t_idx==5, __hdfe1__, .))
                        
                        . egen base= max(cond(t_idx==5, mean_t5, .))
                        
                        . gen coef= __hdfe1__- base 
                        
                        . table (t_idx lang), statistic(mean coef) nototal
                        
                        ----------------------------------------------
                                                          |       Mean
                        ----------------------------------+-----------
                        Event time index (years relative) |           
                          1                               |           
                            group(language)               |           
                              1                           |  -2.368179
                              2                           |  -2.310183
                              3                           |  -2.030731
                          2                               |           
                            group(language)               |           
                              1                           |  -1.670031
                              2                           |  -1.862692
                              3                           |  -1.583619
                          3                               |           
                            group(language)               |           
                              1                           |  -1.563028
                              2                           |  -1.576714
                              3                           |  -1.193569
                          4                               |           
                            group(language)               |           
                              1                           |   -.741419
                              2                           |  -.4857906
                              3                           |  -.6802034
                          5                               |           
                            group(language)               |           
                              1                           |  -.1208417
                              2                           |  -.0481905
                              3                           |   .1726941
                          6                               |           
                            group(language)               |           
                              1                           |   .4780338
                              2                           |   .6149135
                              3                           |   .2160078
                          7                               |           
                            group(language)               |           
                              1                           |   1.535095
                              2                           |   .9207565
                              3                           |   .9523664
                          8                               |           
                            group(language)               |           
                              1                           |   .7677443
                              2                           |   .7492517
                              3                           |   1.199506
                          9                               |           
                            group(language)               |           
                              1                           |   1.656813
                              2                           |   2.412107
                              3                           |   1.538208
                          10                              |           
                            group(language)               |           
                              1                           |   1.955603
                              2                           |   2.651851
                              3                           |   2.017146
                          11                              |           
                            group(language)               |           
                              1                           |   2.862133
                              2                           |    3.03486
                              3                           |   3.112699
                          12                              |           
                            group(language)               |           
                              1                           |   3.043885
                              2                           |   3.347464
                              3                           |   3.188691
                          13                              |           
                            group(language)               |           
                              1                           |   3.966613
                              2                           |   3.903773
                              3                           |   3.539629
                          14                              |           
                            group(language)               |           
                              1                           |   4.276559
                              2                           |   4.516722
                              3                           |   4.233897
                          15                              |           
                            group(language)               |           
                              1                           |   5.216743
                              2                           |   4.904229
                              3                           |   5.309759
                          16                              |           
                            group(language)               |           
                              1                           |   4.721995
                              2                           |   5.363917
                              3                           |   5.330634
                        ----------------------------------------------

                        Comment


                        • #13
                          That’s great, thank you so much.

                          Just to make sure I understand and tie everything up: the two approaches are conceptually equivalent, but using reghdfe plus a prediction step is computationally faster? So if that’s the case, there is no need for me ever to use the full interaction-dummy approach — whether I intend to average across municipalities or not, right?

                          Thanks again for all your help — please let me know if I have misunderstood anything.

                          Comment


                          • #14
                            That's correct: the least squares dummy variable (LSDV) regression and the "within estimator" (as implemented by reghdfe or similar commands) are algebraically equivalent by the Frisch–Waugh theorem. This result is detailed in Frisch and Waugh (Econometrica, 1933). Including a full set of fixed effects via dummy variables produces the same coefficient estimates as using reghdfe, which partials out the fixed effects before estimation. The difference lies purely in computation: reghdfe (or the within transformation more generally) is much more efficient, especially when you have many fixed effects or large datasets. In practice, if you don't need the standard errors of the individual dummy coefficients, there's no reason to use the full interaction-dummy approach. For all other purposes (including averaging across municipalities), the within estimator yields the same results far more efficiently.

                            Reference:
                            Frisch, R., & Waugh, F. V. (1933). Partial Time Regressions as Compared with Individual Trends. Econometrica, 1(4), 387–401.

                            Comment


                            • #15
                              Thank you so much for your incredible help! I really appreciate it.

                              Best, Heike

                              Comment

                              Working...
                              X