I'm using Stata and my panel data set is in the following format:
| year | ID | var1 | var2 |
|---|---|---|---|
| 2000 | 1 | 100 | . |
| 2001 | 1 | 200 | 0.2 |
| 2002 | 1 | 300 | 0.3 |
| 2000 | 2 | 500 | . |
| 2001 | 2 | 300 | 0.4 |
| 2002 | 2 | 400 | 0.1 |
I would like to create an interaction variable between var2 and var1 where the interaction of var2 with var1 is always based on the previous year. In other words, var2 in 2001 should interact with var1 from 2000. Hence, the output should look like this:
| year | ID | var1 | var2 | var1Xvar2 |
|---|---|---|---|---|
| 2000 | 1 | 100 | . | . |
| 2001 | 1 | 200 | 0.2 | 20 |
| 2002 | 1 | 300 | 0.3 | 60 |
| 2000 | 2 | 500 | . | . |
| 2001 | 2 | 300 | 0.4 | 20 |
| 2002 | 2 | 400 | 0.1 | 30 |
How can I achieve this? Thank you for your help!