← See Stata 19's new features
Highlights
Get moderating effects of covariates after hdidregress twfe and xthdidregress twfe
Estimate effects for all covariates or for a subset of covariates in the model
See more causal inference features
Use the new estat moderation command to estimate moderating effects after fitting heterogeneous difference-in-differences (DID) models. This feature is a part of StataNow™.
Researchers using Stata's hdidregress twfe and xthdidregress twfe commands to estimate heterogeneous average treatment effects on the treated (ATETs) are sometimes interested in obtaining moderating effects of covariates, which show how ATETs may vary with covariates.
You can now use the estat moderation postestimation command to report moderating effects of all covariates included in the model or of a subset of interest.
We have fictional future data on American Kennel Club (AKC) registrations and are interested in how the number of registrations of a dog breed, registered, is affected by dogs being the protagonists in a movie, movie. We conjecture that the number of registrations increases if the dog breed appears as the protagonist in a movie. We also conjecture that registrations increase if the dog has won the Best in Show award from the Westminster Kennel Club, best, in the 10 years before 2034.
There are 141 dog breeds in our sample, which extends between the years 2031 and 2040. At the beginning of the sample, none of the breeds are featured in a movie. This changes in 2034, when four breeds are featured in movies. The next year in which we see an increase of breeds featured in movies is 2036, when seven more breeds are featured. In 2037, there is a substantial increase, with 22 more breeds featured. There is no increase in breeds in movies thereafter.
We first load and xtset our data:
. use https://www.stata-press.com/data/r19/akc
(Fictional dog breed and AKC registration data)
. xtset breed year
Panel variable: breed (strongly balanced)
Time variable: year, 2031 to 2040
Delta: 1 unit
We use xthdidregress with the subcommand twfe to estimate ATETs using the two-way fixed-effects estimator.
. xthdidregress twfe (registered best) (movie), group(breed)
note: variable _did_cohort, containing cohort indicators formed by treatment
variable movie and group variable breed, was added to the dataset using
the estimation sample.
Treatment and time information
Time variable: year
Time interval: 2031 to 2040
Control: _did_cohort = 0
Treatment: _did_cohort > 0
| _did_cohort | ||
| Number of cohorts | 4 | |
| Number of obs | ||
| Never treated | 1190 | |
| 2034 | 40 | |
| 2036 | 30 | |
| 2037 | 150 | |
| Robust | ||
| Cohort | ATET std. err. t P>|t| [95% conf. interval] | |
| 2034 | ||
| year | ||
| 2034 | 469.2023 148.8998 3.15 0.002 174.8195 763.5852 | |
| 2035 | 823.8532 211.7491 3.89 0.000 405.2138 1242.493 | |
| 2036 | 1108.669 179.8404 6.16 0.000 753.1144 1464.223 | |
| 2037 | 1752.287 283.487 6.18 0.000 1191.818 2312.756 | |
| 2038 | 2216.617 173.4446 12.78 0.000 1873.708 2559.526 | |
| 2039 | 2433.608 521.4074 4.67 0.000 1402.757 3464.458 | |
| 2040 | 2854.963 494.1892 5.78 0.000 1877.924 3832.001 | |
| 2036 | ||
| year | ||
| 2036 | 1336.121 96.75296 13.81 0.000 1144.835 1527.406 | |
| 2037 | 1343.004 297.7487 4.51 0.000 754.3383 1931.669 | |
| 2038 | 1896.339 399.2574 4.75 0.000 1106.985 2685.692 | |
| 2039 | 2930.344 591.0712 4.96 0.000 1761.765 4098.924 | |
| 2040 | 2565.382 578.9303 4.43 0.000 1420.806 3709.958 | |
| 2037 | ||
| year | ||
| 2037 | 1750.126 216.4288 8.09 0.000 1322.234 2178.017 | |
| 2038 | 2119.908 217.1685 9.76 0.000 1690.554 2549.262 | |
| 2039 | 2506.72 303.9392 8.25 0.000 1905.816 3107.624 | |
| 2040 | 2868.227 313.1679 9.16 0.000 2249.077 3487.377 | |
We are interested in how the ATETs change with the covariate best. We can tabulate the breeds that received Best in Show awards by cohort:
. tabulate best _did_cohort
| Won best | ||||
| in show in | ||||
| past 10 | Treatment-time cohorts | |||
| years | Never tre 2034 2036 2037 | Total | ||
| 0 | 1,110 30 20 150 | 1,310 | ||
| 1 | 80 10 10 0 | 100 | ||
| Total | 1,190 40 30 150 | 1,410 | ||
We see that there were no breeds in the 2037 treatment cohort that received the award, which means that moderating effects cannot be estimated for that cohort. However, we can compute moderating effects for the other cohorts.
. estat moderation
Moderating effects Number of obs = 1,410
R-squared = 0.6127
Adj R-squared = 0.5979
Root MSE = 466.1031
(Std. err. adjusted for 141 clusters in breed)
| Robust | ||
| Effect std. err. t P>|t| [95% conf. interval] | ||
| best | ||
| _did_cohort# | ||
| year | ||
| 2034 2034 | 407.2364 209.0021 1.95 0.053 -5.971938 820.4447 | |
| 2034 2035 | -354.8166 282.82 -1.25 0.212 -913.9668 204.3337 | |
| 2034 2036 | -703.1593 184.46 -3.81 0.000 -1067.847 -338.4719 | |
| 2034 2037 | 1057.35 260.3845 4.06 0.000 542.5554 1572.144 | |
| 2034 2038 | -117.2574 259.8899 -0.45 0.653 -631.0738 396.5589 | |
| 2034 2039 | -1793.078 468.1566 -3.83 0.000 -2718.649 -867.5077 | |
| 2034 2040 | -1804.885 402.4489 -4.48 0.000 -2600.548 -1009.222 | |
| 2036 2036 | -205.6433 182.8762 -1.12 0.263 -567.1993 155.9127 | |
| 2036 2037 | 1017.032 199.0504 5.11 0.000 623.4988 1410.566 | |
| 2036 2038 | -1394.908 175.7055 -7.94 0.000 -1742.287 -1047.529 | |
| 2036 2039 | 396.271 879.6525 0.45 0.653 -1342.849 2135.391 | |
| 2036 2040 | -282.5353 868.8661 -0.33 0.746 -2000.33 1435.26 | |
| 2037 2037 | 0 (omitted) | |
| 2037 2038 | 0 (omitted) | |
| 2037 2039 | 0 (omitted) | |
| 2037 2040 | 0 (omitted) | |
Results are mixed. In the year 2037 for both the 2034 and 2036 cohorts, with effects of 1057.350 and 1017.032 respectively, there is evidence that the ATETs for breeds with Best in Show award were higher than for other breeds. For the rest of the ATETs, results are inconclusive or negative.
Read more in [CAUSAL] hdidregress postestimation in the Stata Causal Inference and Treatment-Effects Estimation Reference Manual.
Learn more about Stata's causal inference features.
View all the new features in Stata 19 and, in particular, new in causal inference.