I got stuck in using forvalues with local values. I have variable x as an integer 1-100. I would like to separate my file based on x. So I summarize x to ret r(min) and r(max) and assign local names.
Here is my example.
However, I get an error from Stata 16.1 as
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.
Are there any ways I can assign the new names to the stored values as local values for Stata 16.1? Kindly let me know.
Best,
Chorthip
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
Comment