I have a challenge with how to create a kind of interaction terms for purposes of running a regression model. I have in my dataset a series of time dummies (for 6 different years) and a series of product dummies (for 5 different products). Taking the year dummies as one group of variable and the product dummy as another group, I want to interact each year with each product. This is because in my model I believe it is appropriate to have these interactions aside having the year and product dummies(indicators) separately . Below is simplified version of my data and its structure:
|
A simplified version of my model is (I have many other independent variables aside product_value) : Yut = b0 + b1product_value + Pu + Tt + Tt 'Pu + eut
In the above equation, Y is Input_Demand by unit u over time t. Pu is the series of product indicators and Tt is the series of year indicators. And Tt 'Pu is the series of interactions I want to create. But my challenge is how do I create the interaction in an automated fashion instead of the manual process of doing it? By manual process I mean something as :
gen p11 = product1*y1
gen p12 = product1*y2
.
.
.
gen p16 = product1*y6
gen p21 = product2*y1
gen p22 = product2*y2
.
.
.
gen p26 = product2*y6
and so on up to
gen p51 = product5*y1
gen p52 = product5*y2
.
.
.
gen p56 = product5*y6
This produces 30 interaction terms.
Is there a way to automate this in the data or in the regression code?
I tried the following code but it does not work. I got the error that says : "product_type: string variables may not be used as factor variables";
. reg Input_Demand product_value i.year##product_type
. reg Input_Demand product_value year ## i.product_type
I used the year and product_type because I do not know how to directly put my year indicators and product indicators in the regression code.
I also tried to put the series of year indicators and also product indicators into separate matrices and then try to do the interaction but then I realized doing a matrix multiplication may not yield the desired interactions. Moreover, because my actual data is quite large (over 20,000 rows), Stata could not even create my matrix.
Please I need help on how to create my interactions and run this regression? Any advice on how to directly put my year indicators and product indicators in the regression code is highly appreciated.
Thank you.
0 Response to Creating interaction terms between a group of year dummies and a group of product dummies and how to use them in a regression equation.
Post a Comment