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?
Related Posts with Creating a loop to count the weeks before and after a policy
Split string variableDear Experts, I want to split the string variable. Please advice. The issue is: I have the respons…
Removing NA Across varI have data in string as shown below data1 data2 NA NA NA NA NA NA NA 8415739 NA 10024002 N 1205788…
Identification of Treatment and Control GroupRespected members, I am trying to employ DID as a means of analysis. In my dataset of 287 firms bet…
Generate var using sequential variables namesHi everyone, p1_1 p1_2 p1_3 p2_1 p2_2 p2_3 p3_1 p3_2 p3_3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 …
Generate sum of variables with sequential variables namesHi everyone, I have a data with these sequential variable names. p1_1_1_1 p1_1_1_2 p1_1_1_3 p1_1…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a loop to count the weeks before and after a policy
Post a Comment