I'm trying to replicate this Stata loop in Pandas:
forvalues i = 1/6 {
gen int codeL`i' = L`i'.location_level_2
gen int codeF`i' = F`i'.location_level_2
}
As you can see, I want to create these new columns: codeL1 code L2...and so on, until I get codeL6, based on the lags and leads of the variable location_level_2
It is kind of easy in Stata, but as I'm just starting in Pandas, I have no clue.
This would be my attempt:
for i in range(1,7):
df[codeLi] = df[location_level_2].shift(i)
for i in range(-1,-7):
df[codeLi] = df[location_level_2].shift(i)