Hi,
I have a loop that goes over different values, and inside the loop I create a variable with a specific suffix for each value. My problem is that I have negative numbers in the loop, and Stata does not allow negative numbers to be part of a variable name. What I am trying to do is to create another local inside the loop, which would have a conditional value based on whether the original value is negative or not. Here is what I've done so far, but it does not work.
Any help is highly appreciated. Best,
Albert
I have a loop that goes over different values, and inside the loop I create a variable with a specific suffix for each value. My problem is that I have negative numbers in the loop, and Stata does not allow negative numbers to be part of a variable name. What I am trying to do is to create another local inside the loop, which would have a conditional value based on whether the original value is negative or not. Here is what I've done so far, but it does not work.
Code:
forvalues i = -10(1)10 { di `i' local k cond(`i'<0,"minus_"substr("`i'",-1,.),`i') gen var_`k' = . }
Albert
Comment