I am trying to bottom and top coding the household income for each country - wave.
I am using the following loop that I already successfully used with another data source:
levelsof country, local(c)
levelsof wave, local(w)
foreach country in `c' {
foreach wave in `w' {
sum hi100_equ [aw=new_weight] if country==`country' & wave==`wave', det
local bottom_hi=r(mean)/100
sum hi100_eur [aw=new_weight] if country==`country' & wave==`wave', det
local top_dhi=10*r(p50)
disp `bottom_hi'
disp `top_hi'
replace adjusted_hi=`top_hi' if hi100_eur>`$top_hi' & country==`country' & wave==`wave'
replace adjusted_hi=`bottom_hi' if hi100_eur<`$bottom_hi' & country==`country' & wave==`wave'
}
}
levelsof wave, local(w)
foreach country in `c' {
foreach wave in `w' {
sum hi100_equ [aw=new_weight] if country==`country' & wave==`wave', det
local bottom_hi=r(mean)/100
sum hi100_eur [aw=new_weight] if country==`country' & wave==`wave', det
local top_dhi=10*r(p50)
disp `bottom_hi'
disp `top_hi'
replace adjusted_hi=`top_hi' if hi100_eur>`$top_hi' & country==`country' & wave==`wave'
replace adjusted_hi=`bottom_hi' if hi100_eur<`$bottom_hi' & country==`country' & wave==`wave'
}
}
However, Stata returns the following error: if not found.
I cannot understand what's the error, can anyone help me?
Thank you
0 Response to Replace if not found within a loop
Post a Comment