Hi,

I'm working on understanding the impact of a hospital policy on healthcare utilization. The policy was implemented in March of 2020. I need to create variable that increases by 1 for every week after the policy and decreases by 1 for every week before the policy. I know I could do it by creating a lot of replace statements e.g.

gen policy_week=0 if week==11 & year==2020
replace policy_week=1 if week==12 & year==2020
replace policy_week=2 if week==13 & year==2020
replace policy_week=3 if week==14 & year==2020
replace policy_week=4 if week==15 & year==2020
.
.
.
replace policy_week=-1 if week==10 & year==2020
replace policy_week=-2 if week==9 & year==2020
replace policy_week=-3if week==8 & year==2020
replace policy_week=-4 if week==7 & year==2020

But I would like to try it doing a loop. Any guidance on how to best do this?