Yes, you interact the indicators with the group dummy.
Check that you obtain the same coefficients (of the time-varying regressors) as with the separate regressions.
Code:
i.group#i.year
. ivreghdfe F1.ln_rd_test (law_change law_change_x_index = raw_mil_spend right left) index /// > $c1 $c2 /// > i.year if f_new_slack <= -0.57 & !missing(F1.ln_rd_test) & flag==1 , absorb(id) cluster(countryfind) (dropped 1907 singleton observations) Warning: time variable year has 5639 gap(s) in relevant range (MWFE estimator converged in 1 iterations) IV (2SLS) estimation -------------------- Estimates efficient for homoskedasticity only Statistics robust to heteroskedasticity and clustering on countryfind Number of clusters (countryfind) = 3166 Number of obs = 81300 F( 37, 3165) = 13.88 Prob > F = 0.0000 Total (centered) SS = 222346.0539 Centered R2 = -0.8173 Total (uncentered) SS = 222346.0539 Uncentered R2 = -0.8173 Residual SS = 404071.8436 Root MSE = 2.23 -------------------------------------------------------------------------------------------- | Robust F.ln_rd_test | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------------------------+---------------------------------------------------------------- law_change | 25.32246 10.3543 2.45 0.015 5.020641 45.62427 law_change_x_index | -2.792538 1.303726 -2.14 0.032 -5.348773 -.236304 index | .1560371 .0773903 2.02 0.044 .0042969 .3077772 ln_at | .2096393 .0826948 2.54 0.011 .0474984 .3717801 roe | .000109 .0003717 0.29 0.769 -.0006198 .0008378 mb_ratio | .0076536 .0038667 1.98 0.048 .0000722 .0152351 f_new_slack | .4888829 .1202997 4.06 0.000 .2530096 .7247563 ind_dir | -.3053586 .4885585 -0.63 0.532 -1.263282 .6525648 dual_ceo | .2260202 .1165518 1.94 0.053 -.0025045 .4545449 f_io | 1.228445 .3948162 3.11 0.002 .4543238 2.002567 inside_own | -.0489555 .2552572 -0.19 0.848 -.5494418 .4515308 EPI | 1.66099 2.08973 0.79 0.427 -2.436373 5.758352 product_diversification | .0418677 .075209 0.56 0.578 -.1055955 .189331 geographic_diversification | .1362127 .0862731 1.58 0.114 -.0329442 .3053697 hhi | .0611796 .2897922 0.21 0.833 -.50702 .6293793 wto2 | -.352277 .2066349 -1.70 0.088 -.7574289 .0528749 imp_pen | -.0168087 .0174068 -0.97 0.334 -.0509385 .017321 f_subsidy | 3.887572 .9088558 4.28 0.000 2.105566 5.669578 len_law | -.4191377 .3418021 -1.23 0.220 -1.089314 .2510384 board_reform | -.0970008 .1304 -0.74 0.457 -.3526779 .1586764 gdp_growth_rate | -.020974 .0168347 -1.25 0.213 -.053982 .012034 | year | 2000 | 0 (empty) 2001 | 1.008631 .5770072 1.75 0.081 -.1227153 2.139977 2002 | -.0255344 .1002906 -0.25 0.799 -.2221755 .1711067 2003 | -.0053112 .1374453 -0.04 0.969 -.2748021 .2641797 2004 | .0363258 .1555268 0.23 0.815 -.2686177 .3412693 2005 | .2218425 .2431436 0.91 0.362 -.2548925 .6985775 2006 | .1321908 .278427 0.47 0.635 -.4137249 .6781066 2007 | .1363553 .3720799 0.37 0.714 -.5931869 .8658975 2008 | -.6383366 .4754139 -1.34 0.179 -1.570487 .293814 2009 | -.5267984 .4469447 -1.18 0.239 -1.403129 .3495324 2010 | -.4158678 .4454783 -0.93 0.351 -1.289323 .4575877 2011 | -.1949794 .4026001 -0.48 0.628 -.984363 .5944041 2012 | -.0980417 .4138091 -0.24 0.813 -.9094029 .7133195 2013 | .0814712 .4115376 0.20 0.843 -.7254362 .8883786 2014 | .1027701 .4088825 0.25 0.802 -.6989315 .9044717 2015 | .0636774 .4098529 0.16 0.877 -.7399268 .8672817 2016 | .1435507 .404009 0.36 0.722 -.6485953 .9356967 . ivreghdfe F1.ln_rd_test (law_change law_change_x_index = raw_mil_spend right left) index /// > $c1 $c2 /// > i.year if f_new_slack > -0.57 & !missing(F1.ln_rd_test) & flag==1 , absorb(id) cluster(countryfind) (dropped 1829 singleton observations) Warning: time variable year has 5602 gap(s) in relevant range (MWFE estimator converged in 1 iterations) IV (2SLS) estimation -------------------- Estimates efficient for homoskedasticity only Statistics robust to heteroskedasticity and clustering on countryfind Number of clusters (countryfind) = 2747 Number of obs = 82269 F( 37, 2746) = 16.55 Prob > F = 0.0000 Total (centered) SS = 211861.0826 Centered R2 = -0.4039 Total (uncentered) SS = 211861.0826 Uncentered R2 = -0.4039 Residual SS = 297426.839 Root MSE = 1.902 -------------------------------------------------------------------------------------------- | Robust F.ln_rd_test | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------------------------+---------------------------------------------------------------- law_change | 16.74597 6.540438 2.56 0.011 3.921291 29.57064 law_change_x_index | -1.869139 .8230401 -2.27 0.023 -3.482979 -.2552987 index | .0981082 .0766398 1.28 0.201 -.0521692 .2483856 ln_at | .0212561 .0061007 3.48 0.001 .0092936 .0332185 roe | .0002032 .0004174 0.49 0.626 -.0006153 .0010217 mb_ratio | .0064985 .004255 1.53 0.127 -.0018449 .0148419 f_new_slack | -.016509 .0092886 -1.78 0.076 -.0347223 .0017043 ind_dir | .4026915 .3090145 1.30 0.193 -.2032328 1.008616 dual_ceo | .0775164 .1301567 0.60 0.552 -.1776985 .3327312 f_io | 2.089106 .3069762 6.81 0.000 1.487178 2.691033 inside_own | -.1930502 .1672237 -1.15 0.248 -.5209472 .1348468 EPI | 1.507155 2.10709 0.72 0.474 -2.624487 5.638797 product_diversification | .1275532 .0618039 2.06 0.039 .0063664 .24874 geographic_diversification | .1280742 .0704102 1.82 0.069 -.009988 .2661365 hhi | .2497523 .2137538 1.17 0.243 -.1693821 .6688867 wto2 | -.3531912 .1778374 -1.99 0.047 -.7018998 -.0044825 imp_pen | -.0121328 .0152971 -0.79 0.428 -.0421278 .0178621 f_subsidy | 3.947427 .8536893 4.62 0.000 2.273489 5.621365 len_law | -.4881133 .2350491 -2.08 0.038 -.9490042 -.0272223 board_reform | -.209268 .1205664 -1.74 0.083 -.4456781 .0271421 gdp_growth_rate | -.0212426 .0141153 -1.50 0.132 -.0489203 .0064351 | year | 2000 | 0 (empty) 2001 | .5452407 .6126857 0.89 0.374 -.6561308 1.746612 2002 | -.1956868 .0871949 -2.24 0.025 -.366661 -.0247125 2003 | -.0947303 .1295358 -0.73 0.465 -.3487278 .1592671 2004 | .0224613 .1328724 0.17 0.866 -.2380786 .2830012 2005 | .1857015 .1426177 1.30 0.193 -.0939472 .4653503 2006 | .1275872 .1437392 0.89 0.375 -.1542606 .409435 2007 | -.010257 .2044049 -0.05 0.960 -.4110599 .3905459 2008 | -.6701139 .3309831 -2.02 0.043 -1.319115 -.0211129 2009 | -.4908864 .2764831 -1.78 0.076 -1.033022 .0512494 2010 | -.2979535 .2839611 -1.05 0.294 -.8547524 .2588453 2011 | -.0666279 .2656592 -0.25 0.802 -.5875399 .4542841 2012 | .0759122 .2750827 0.28 0.783 -.4634777 .615302 2013 | .1711425 .2782354 0.62 0.539 -.3744293 .7167144 2014 | .2247773 .2866682 0.78 0.433 -.3373299 .7868845 2015 | .2485466 .298769 0.83 0.406 -.337288 .8343812 2016 | .338815 .3088073 1.10 0.273 -.266703 .944333 IV (2SLS) estimation -------------------- Estimates efficient for homoskedasticity only Statistics robust to heteroskedasticity and clustering on countryfind Number of clusters (countryfind) = 3824 Number of obs = 167305 F( 75, 3823) = 14.75 Prob > F = 0.0000 Total (centered) SS = 493526.1119 Centered R2 = -0.8944 Total (uncentered) SS = 493526.1119 Uncentered R2 = -0.8944 Residual SS = 934936.8007 Root MSE = 2.364 ---------------------------------------------------------------------------------------------------- | Robust F.ln_rd_test | Coef. Std. Err. t P>|t| [95% Conf. Interval] -----------------------------------+---------------------------------------------------------------- law_change | 31.07561 14.58592 2.13 0.033 2.478681 59.67255 | group#c.law_change | 1 | 0 (empty) 2 | -11.75236 13.65669 -0.86 0.390 -38.52745 15.02274 | law_change_x_index | -2.472403 1.737462 -1.42 0.155 -5.878843 .9340383 | group#c.law_change_x_index | 1 | 0 (empty) 2 | .0428597 1.657364 0.03 0.979 -3.206544 3.292263 | index | .1291419 .0801277 1.61 0.107 -.0279553 .2862392 | group#c.index | 1 | 0 (empty) 2 | .016126 .0176944 0.91 0.362 -.0185654 .0508175 | group | 1 | 0 (empty) 2 | .7637542 .4791118 1.59 0.111 -.1755851 1.703093 | ln_at | .0799501 .0222958 3.59 0.000 .0362373 .1236628 roe | -.000175 .0004584 -0.38 0.703 -.0010738 .0007237 mb_ratio | .0107684 .0040241 2.68 0.007 .0028788 .0186581 f_new_slack | .5160733 .1161133 4.44 0.000 .2884234 .7437231 ind_dir | .0036234 .3841846 0.01 0.992 -.749603 .7568498 dual_ceo | .2033903 .1187965 1.71 0.087 -.0295203 .4363008 f_io | 1.961082 .4098113 4.79 0.000 1.157613 2.764552 inside_own | -.1299047 .2123404 -0.61 0.541 -.546216 .2864066 EPI | 1.357255 2.211224 0.61 0.539 -2.978037 5.692546 product_diversification | .1629214 .0745022 2.19 0.029 .0168535 .3089894 geographic_diversification | .1501942 .0830202 1.81 0.071 -.0125739 .3129623 hhi | .2494026 .208423 1.20 0.232 -.1592283 .6580336 wto2 | -.5676854 .2393127 -2.37 0.018 -1.036878 -.0984925 imp_pen | -.0104726 .0160281 -0.65 0.514 -.0418972 .0209519 f_subsidy | 4.523308 .9607441 4.71 0.000 2.639688 6.406929 len_law | -.2842486 .3352233 -0.85 0.397 -.9414823 .3729852 board_reform | -.1830068 .1282257 -1.43 0.154 -.4344042 .0683905 gdp_growth_rate | -.0202132 .0195846 -1.03 0.302 -.0586105 .0181841 | group#c.ln_at | 1 | 0 (empty) 2 | -.0549193 .0204824 -2.68 0.007 -.0950769 -.0147618 | group#c.roe | 1 | 0 (empty) 2 | .0002609 .000616 0.42 0.672 -.0009469 .0014687 | group#c.mb_ratio | 1 | 0 (empty) 2 | -.0084304 .0059786 -1.41 0.159 -.020152 .0032913 | group#c.f_new_slack | 1 | 0 (empty) 2 | -.5303193 .1163189 -4.56 0.000 -.7583722 -.3022663 | group#c.ind_dir | 1 | 0 (empty) 2 | -.0555966 .1388342 -0.40 0.689 -.3277929 .2165996 | group#c.dual_ceo | 1 | 0 (empty) 2 | -.0717037 .1298745 -0.55 0.581 -.3263337 .1829263 | group#c.f_io | 1 | 0 (empty) 2 | .0905368 .2145112 0.42 0.673 -.3300305 .5111041 | group#c.inside_own | 1 | 0 (empty) 2 | .0163545 .1064903 0.15 0.878 -.1924287 .2251378 | group#c.EPI | 1 | 0 (empty) 2 | -.0752117 .3124562 -0.24 0.810 -.6878085 .5373852 | group#c.product_diversification | 1 | 0 (empty) 2 | -.0983751 .0760269 -1.29 0.196 -.2474323 .0506821 | group#c.geographic_diversification | 1 | 0 (empty) 2 | -.0200561 .0724178 -0.28 0.782 -.1620373 .1219251 | group#c.hhi | 1 | 0 (empty) 2 | -.0482393 .1227677 -0.39 0.694 -.2889358 .1924572 | group#c.wto2 | 1 | 0 (empty) 2 | .0728838 .2228353 0.33 0.744 -.3640037 .5097713 | group#c.imp_pen | 1 | 0 (empty) 2 | -.0008665 .0022621 -0.38 0.702 -.0053015 .0035684 | group#c.f_subsidy | 1 | 0 (empty) 2 | .0224975 .4914626 0.05 0.963 -.9410564 .9860515 | group#c.len_law | 1 | 0 (empty) 2 | -.3091903 .1682742 -1.84 0.066 -.6391062 .0207257 | group#c.board_reform | 1 | 0 (empty) 2 | .1924981 .1070262 1.80 0.072 -.0173359 .4023321 | group#c.gdp_growth_rate | 1 | 0 (empty) 2 | -.0131262 .0198884 -0.66 0.509 -.0521192 .0258667 | year#group | 2000 1 | 0 (empty) 2000 2 | 0 (empty) 2001 1 | .8118205 .6035719 1.35 0.179 -.3715333 1.995174 2001 2 | .8848999 .62551 1.41 0.157 -.3414655 2.111265 2002 1 | -.0915283 .1166714 -0.78 0.433 -.3202724 .1372158 2002 2 | -.247155 .0876288 -2.82 0.005 -.4189586 -.0753514 2003 1 | -.0853764 .1471558 -0.58 0.562 -.3738878 .2031351 2003 2 | -.226818 .1329079 -1.71 0.088 -.4873952 .0337592 2004 1 | -.0651613 .1664226 -0.39 0.695 -.3914468 .2611242 2004 2 | -.1004822 .1356631 -0.74 0.459 -.3664612 .1654968 2005 1 | .1330681 .2347039 0.57 0.571 -.3270888 .593225 2005 2 | .099037 .1577635 0.63 0.530 -.2102718 .4083458 2006 1 | -.0244321 .2691714 -0.09 0.928 -.5521655 .5033013 2006 2 | .0310258 .1503983 0.21 0.837 -.2638428 .3258944 2007 1 | -.2307835 .384779 -0.60 0.549 -.9851753 .5236082 2007 2 | .041318 .207538 0.20 0.842 -.3655778 .4482139 2008 1 | -1.098977 .5787491 -1.90 0.058 -2.233664 .0357092 2008 2 | -.706679 .3734442 -1.89 0.059 -1.438848 .02549 2009 1 | -.9768146 .5336957 -1.83 0.067 -2.02317 .0695411 2009 2 | -.4767734 .2765865 -1.72 0.085 -1.019045 .0654978 2010 1 | -.883493 .5546134 -1.59 0.111 -1.97086 .2038735 2010 2 | -.2630056 .283376 -0.93 0.353 -.8185882 .2925769 2011 1 | -.6078853 .4633913 -1.31 0.190 -1.516403 .3006327 2011 2 | -.0437432 .2626279 -0.17 0.868 -.5586475 .4711612 2012 1 | -.4994978 .4631112 -1.08 0.281 -1.407467 .4084709 2012 2 | .1010796 .2737166 0.37 0.712 -.4355649 .6377241 2013 1 | -.3053716 .4663349 -0.65 0.513 -1.219661 .6089174 2013 2 | .2037734 .2806061 0.73 0.468 -.3463787 .7539255 2014 1 | -.2624437 .4677977 -0.56 0.575 -1.179601 .6547133 2014 2 | .2498726 .2891235 0.86 0.388 -.3169785 .8167236 2015 1 | -.312802 .4911589 -0.64 0.524 -1.275761 .6501566 2015 2 | .2856399 .2933452 0.97 0.330 -.2894882 .8607679 2016 1 | -.2049168 .4860419 -0.42 0.673 -1.157843 .7480096 2016 2 | .3593119 .3032452 1.18 0.236 -.2352259 .9538498 . test 1.group#c.law_change_x_index= 2.group#c.law_change_x_index ( 1) 1b.group#co.law_change_x_index - 2.group#c.law_change_x_index = 0 F( 1, 3823) = 0.00 Prob > F = 0.9794
webuse hsng2, clear set seed 08192024 gen rent2= rent + rnormal(30, 5) ivregress 2sls rent pcturban (hsngval = faminc), robust ivregress 2sls rent2 pcturban (hsngval = faminc), robust gmm (eq1: rent - {xb1: hsngval pcturban} - {b0}) /// (eq2: rent2- {xb2:hsngval pcturban} - {c0}), /// instruments(eq1: pcturban faminc) /// instruments(eq2: pcturban faminc) /// onestep winitial(unadjusted, indep) test _b[xb1:hsngval]=_b[xb2:hsngval]
. ivregress 2sls rent pcturban (hsngval = faminc), robust Instrumental variables 2SLS regression Number of obs = 50 Wald chi2(2) = 32.55 Prob > chi2 = 0.0000 R-squared = 0.2887 Root MSE = 29.517 ------------------------------------------------------------------------------ | Robust rent | Coefficient std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- hsngval | .0031938 .000738 4.33 0.000 .0017474 .0046402 pcturban | -.5064118 .5428297 -0.93 0.351 -1.570339 .5575149 _cons | 113.8143 21.62169 5.26 0.000 71.43659 156.1921 ------------------------------------------------------------------------------ Endogenous: hsngval Exogenous: pcturban faminc . ivregress 2sls rent2 pcturban (hsngval = faminc), robust Instrumental variables 2SLS regression Number of obs = 50 Wald chi2(2) = 32.16 Prob > chi2 = 0.0000 R-squared = 0.2015 Root MSE = 32.069 ------------------------------------------------------------------------------ | Robust rent2 | Coefficient std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- hsngval | .0033152 .0007076 4.68 0.000 .0019283 .0047021 pcturban | -.5196499 .5255934 -0.99 0.323 -1.549794 .5104942 _cons | 139.3851 23.6452 5.89 0.000 93.04131 185.7288 ------------------------------------------------------------------------------ Endogenous: hsngval Exogenous: pcturban faminc . . gmm (eq1: rent - {xb1: hsngval pcturban} - {b0}) /// > (eq2: rent2- {xb2:hsngval pcturban} - {c0}), /// > instruments(eq1: pcturban faminc) /// > instruments(eq2: pcturban faminc) /// > onestep winitial(unadjusted, indep) Step 1: Iteration 0: GMM criterion Q(b) = 127377.61 Iteration 1: GMM criterion Q(b) = 1.318e-20 Iteration 2: GMM criterion Q(b) = 1.641e-26 note: model is exactly identified. GMM estimation Number of parameters = 6 Number of moments = 6 Initial weight matrix: Unadjusted Number of obs = 50 ------------------------------------------------------------------------------ | Robust | Coefficient std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- xb1 | hsngval | .0031938 .0007379 4.33 0.000 .0017475 .0046401 pcturban | -.5064118 .5428077 -0.93 0.351 -1.570295 .5574717 -------------+---------------------------------------------------------------- b0 | _cons | 113.8143 21.6214 5.26 0.000 71.43716 156.1915 -------------+---------------------------------------------------------------- xb2 | hsngval | .0033152 .0007077 4.68 0.000 .0019281 .0047023 pcturban | -.5196499 .5256147 -0.99 0.323 -1.549836 .5105359 -------------+---------------------------------------------------------------- /c0 | 139.3851 23.64563 5.89 0.000 93.04047 185.7296 ------------------------------------------------------------------------------ Instruments for equation eq1: pcturban faminc _cons Instruments for equation eq2: pcturban faminc _cons . . test _b[xb1:hsngval]=_b[xb2:hsngval] ( 1) [xb1]hsngval - [xb2]hsngval = 0 chi2( 1) = 1.45 Prob > chi2 = 0.2284 . .
Comment