I have a data set that looks like this:
A B
0 1
0 1
0 1
1 0
I want to create new variables A't' and B't' for t=1,2,3 that give A and B values for the past 1,2 and 3 periods. I tried the following code but I get the error: "A invalid name.
local status A B
foreach x of local status {
forvalues t=1/3 {
gen "`x'"`t'="`x'"[_n-`t'] if _n>`t'
}
}
And the outcome I would like to get is the following:
A B A1 A2 A3 B1 B2 B3
0 1 . . . . . .
1 0 0 . . 1 . .
0 1 1 0 . 0 1 .
1 0 0 1 0 1 0 1