Hello everyone.
I have a question regarding the interaction of a dummy with a continuous variable in a regression.
I noticed that when I run the following commands
I get the following output which is puzzling because I have a value for i.dum#c.x2 when dum=0
I understood that is the same result when I include also x2 alone in a regression like:
so it is like adding the x2 variable alone.
Is there a way to write the regression so that i.dum is interacted with x2 but omitting the calculation for i.dum#c.x2 when dum=0 ?
I know I could manually write a new variable like dum_x2=dum*x2, but I need to keep them separated to calculate margins with the margins code
Any help would be so much appreciated!
I have a question regarding the interaction of a dummy with a continuous variable in a regression.
I noticed that when I run the following commands
Code:
clear all set obs 1000 set seed 123 gen y=rnormal() gen x2=rnormal() gen dum = runiform() > 0.5 reg y i.dum i.dum#c.x2
Code:
Source | SS df MS Number of obs = 1,000
-------------+---------------------------------- F(3, 996) = 2.11
Model | 5.95919858 3 1.98639953 Prob > F = 0.0974
Residual | 937.796739 996 .941562991 R-squared = 0.0063
-------------+---------------------------------- Adj R-squared = 0.0033
Total | 943.755937 999 .944700638 Root MSE = .97034
------------------------------------------------------------------------------
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
1.dum | -.1102455 .0614268 -1.79 0.073 -.2307863 .0102952
|
dum#c.x2 |
0 | .07283 .0439866 1.66 0.098 -.0134871 .159147
1 | -.0318478 .0414672 -0.77 0.443 -.1132208 .0495252
|
_cons | .0769639 .043772 1.76 0.079 -.0089321 .1628599
------------------------------------------------------------------------------
Code:
reg y i.dum i.dum#c.x2 x2
Is there a way to write the regression so that i.dum is interacted with x2 but omitting the calculation for i.dum#c.x2 when dum=0 ?
I know I could manually write a new variable like dum_x2=dum*x2, but I need to keep them separated to calculate margins with the margins code
Any help would be so much appreciated!

Comment