Dear stata users,
I have the following code
where "mv" is the variable for which I create 5 quantile categories and k=433 (the "yearmonth" variable which I loop over has 433 observations).
I face a problem. There are missing values for some i's (each yearmonth iteration). For instance, `i'=50 and `i'=51 are missing so whenever the program reaches the 49th execution I get this message:
"nquantiles() must be less than or equal to number of observations plus one",
which clearly refers to the number of quantiles because I think since there is no yearmonth, there are also no quantiles in the 50th execution.
so..
1. Is there a way to skip the missing values in the loop so that it continues to let's say the 52nd execution?
2. Is there a way to take into account the fact that there might be less than 6 observations so as to skip the xtile command and leave mvq=. ?
I tried
but I it doesn't work.
Thank you,
Stylia
I have the following code
Code:
gen mvq=. egen yearmonth = group(year month) sum yearmonth scalar maxy =r(max) local k=maxy egen nobs3 =count(mv), by(yearmonth) forvalues i=1(1) `k' { qui xtile xmv=mv if yearmonth==`i' , nq(5) qui replace mvq=xmv if yearmonth==`i' qui drop xmv }
where "mv" is the variable for which I create 5 quantile categories and k=433 (the "yearmonth" variable which I loop over has 433 observations).
I face a problem. There are missing values for some i's (each yearmonth iteration). For instance, `i'=50 and `i'=51 are missing so whenever the program reaches the 49th execution I get this message:
"nquantiles() must be less than or equal to number of observations plus one",
which clearly refers to the number of quantiles because I think since there is no yearmonth, there are also no quantiles in the 50th execution.
so..
1. Is there a way to skip the missing values in the loop so that it continues to let's say the 52nd execution?
2. Is there a way to take into account the fact that there might be less than 6 observations so as to skip the xtile command and leave mvq=. ?
I tried
Code:
qui xtile xmv=mv if yearmonth==`i' & nobs3 >=6, nq(5)
Thank you,
Stylia
Comment