My date variable (x11) is in the format:%td. I am trying to filter out a sub sample of my data conditional on date. The condition being as follows:
keep if x11>=td(15oct2020)& x11<=td(21oct2020)
This creates a data set of observations within these dates. I want to automate this process by creating a loop for Stata to automatically pick up date x (i.e 15oct2020) in the first condition and add 7 days to it with y=x+7 and plug into the above condition to filter out the relevant dates. I am unsure of how to automate this process using a loop. Please help.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str11 x4 str30 resp_name str10 resp_phno double x11 float bcstatus "TAMIL NADU" "K " "9?????6" 22205 1 "TAMIL NADU" "M" "9?????7" 22203 1 "TAMIL NADU" "P" "6?????0" 22206 1 "TAMIL NADU" " N" "9?????1" 22204 1 "TAMIL NADU" "U" "9??????8" 22204 1 "TAMIL NADU" "S" "8?????4" 22208 1 "TAMIL NADU" "PR" "9?????4" 22206 1 "TAMIL NADU" "K " "8??????7" 22203 1 "TAMIL NADU" "AM" "9???????5" 22209 1 "TAMIL NADU" "MA" "8???????6" 22203 1 end format %td x11
0 Response to Creating loop on date variable
Post a Comment