Here is my example.
Code:
use "${UPDATE2020}abcd-wip01.dta", clear
summ x, detail
local low=r(min)
local hi=r(max)
forvalues i=`low'/`hi' {
use "${UPDATE2020}abcd-wip01.dta", clear
di "keep `i'"
keep if x==`i'
saveold "${UPDATE2020}tariff-wip01-keep`i'.dta", replace
}invalid syntax
r(198);
I have no clues why giving the name for r(min)/r(max) gives an error to the code. I used the code above for Stata 13.1 a year ago and it worked fine. Kindly let me know if there is any change in Stata Syntax I should know.
Strangely, when I use r(min)/r(max) directly to this code, it works fine for me.
Code:
use "${UPDATE2020}abcd-wip01.dta", clear
summ x, detail
forvalues i=`r(min)'/`r(max)' {
use "${UPDATE2020}abcd-wip01.dta", clear
di "keep `i'"
keep if x==`i'
saveold "${UPDATE2020}abcd-wip01-keep`i'.dta", replace
}Best,
Chorthip
0 Response to forvalues loop with the use of local values
Post a Comment