I'm working with house price indices, so I have a big loop with other loops inside. This is because I have information from online listings for each city in a particular month of a particular year.
In the following code, i stands for city, m stands for month and y stands for year. The loop is much longer, but in this first part I calculate the amount of observations in the treated group and in the control group. I'm trying to omit the months where I have less than 50 observations either in the treated or in the control group and for that I'm using "continue, break". The problem is that these lines continue the loop in the next year, not in the next month. For example, if I didn't have enough observations in city 1, may, 2018, instead of jumping to city 1, june 2018, it jumps to city 1, january 2019. So whenever I have a month that "breaks" the loop, it breaks it to the next year and I miss all of the other months that come next.
Does anybody have a better idea of how to solve this issue?
The example of the code that I'm using is the following:
(preciouf is the price variable, and NUMB_T stands for number treated, and NUMB_N for the non treated
In the following code, i stands for city, m stands for month and y stands for year. The loop is much longer, but in this first part I calculate the amount of observations in the treated group and in the control group. I'm trying to omit the months where I have less than 50 observations either in the treated or in the control group and for that I'm using "continue, break". The problem is that these lines continue the loop in the next year, not in the next month. For example, if I didn't have enough observations in city 1, may, 2018, instead of jumping to city 1, june 2018, it jumps to city 1, january 2019. So whenever I have a month that "breaks" the loop, it breaks it to the next year and I miss all of the other months that come next.
Does anybody have a better idea of how to solve this issue?
The example of the code that I'm using is the following:
(preciouf is the price variable, and NUMB_T stands for number treated, and NUMB_N for the non treated
Code:
local i=1 while `i'<14{ local y=2017 while `y'<2021{ local m=1 while `m'<5{ insheet using "${pathData}`i'_`y'_`m'.csv", comma clear * getting number of control and treated before matching tabstat preciouf, stat(count) save, if treated==1 matrix NumbB_T=r(StatTotal) tabstat preciouf, stat(count) save, if treated==0 matrix NumbB_NT =r(StatTotal)' matrix NumbB=(NumbB_T, NumbB_NT) mat rown NumbB = "`y' `m'" mat coln NumbB = Before local c=NumbB_T[1,1] local z=NumbB_NT[1,1] mat rown NumbB_T = "i_`y'_`m'" mat rown NumbB_NT = "i_`y'_`m'" mat2txt , m(NumbB_T) sav("${pathRes}NumbB_T.txt") append if (`c'<50) continue, break if (`z'<50) continue, break *** everything else local m=`m'+1 } local y=`y'+1 } local i=`i'+1 }
Comment