I want to know how to create a variable that stores the value of a macro. The most simple example would be something along the lines of storing the value of i' in a forvalues` loop below.
forvalues i = 1/10 {
dis `i'
}
As far as I know, I can generate variables whose name are in the format name'i' but not directly storing the value of i to another variable. What I want to do ultimately is to create a year variable that stores, obviously, the year of the dataset using a loop:
forvalues i = 2000/2020 {
use dataset`i'
gen year`i' = `i'
*gen year`i' = "`i'" ***this did not work either
}
The above code generates a bunch of
year`i'
with 0 or NULL values.