Hello,

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:


year BusinessUnit_id Input_Demand product_type product_value product1 product2 product3 product4 product5 y1 y2 y3 y4 y5 y6
2000 I198 50 EE 138.0183 0 0 0 0 1 1 0 0 1 0 0
2002 T151 45 EE 75.98437 0 0 0 0 1 0 1 0 0 0 0
2002 A278 13 DD 14.40479 0 0 0 1 0 0 1 0 0 0 0
2003 I151 60 AA 138.7325 1 0 0 0 0 0 0 1 0 0 0
2004 S104 28 DD 73.46765 0 0 0 1 0 0 0 0 1 0 0
2007 H870 67 CC 138.8444 0 0 1 0 0 0 0 0 0 0 1
2006 H112 13 EE 37.98688 0 0 0 0 1 0 0 0 0 1 0
2006 B875 36 DD 129.4648 0 0 0 1 0 0 0 0 0 1 0
2004 S105 80 EE 139.6111 0 0 0 0 1 0 0 0 1 0 0
2007 H646 29 BB 104.808 0 1 0 0 0 0 0 0 0 0 1
2002 A140 20 CC 31.71127 0 0 1 0 0 0 1 0 0 0 0
2004 B876 37 AA 128.3044 1 0 0 0 0 0 0 0 1 0 0
2007 S106 130 DD 142.0531 0 0 0 1 0 0 0 0 0 0 1
2006 H212 55 BB 111.6184 0 1 0 0 0 0 0 0 0 1 0


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.