What you want is not possible. In Stata there are rules about variable names, e.g., they cannot have spaces in, and they cannot start with numbers.
So if you want to create variables with city names, you need to change the city names.
Another possibility is to create variables with some names, but to label the variables with the city names. Something like this:
In the above I generated variables var1-var5, but the names of the cities (in my example of car makes) are in the variable labels.
It depend on what you want to do next, but you really have no other choice but:
1. To change city names if you want to call variables like the cities.
2. Move the city names to the variable labels.
So if you want to create variables with city names, you need to change the city names.
Another possibility is to create variables with some names, but to label the variables with the city names. Something like this:
Code:
. sysuse auto, clear (1978 Automobile Data) . keep in 1/10 (64 observations deleted) . sysuse auto, clear (1978 Automobile Data) . keep in 1/5 (69 observations deleted) . keep make . forvalues i=1/`=_N' { 2. gen var`i'=. 3. label var var`i' "`=make[`i']'" 4. } (5 missing values generated) (5 missing values generated) (5 missing values generated) (5 missing values generated) (5 missing values generated) . list, sep(0) +--------------------------------------------------+ | make var1 var2 var3 var4 var5 | |--------------------------------------------------| 1. | AMC Concord . . . . . | 2. | AMC Pacer . . . . . | 3. | AMC Spirit . . . . . | 4. | Buick Century . . . . . | 5. | Buick Electra . . . . . | +--------------------------------------------------+ . des Contains data from C:\Program Files (x86)\Stata15\ado\base/a/auto.dta obs: 5 1978 Automobile Data vars: 6 13 Apr 2016 17:45 size: 190 (_dta has notes) ---------------------------------------------------------------------------------------------------- storage display value variable name type format label variable label ---------------------------------------------------------------------------------------------------- make str18 %-18s Make and Model var1 float %9.0g AMC Concord var2 float %9.0g AMC Pacer var3 float %9.0g AMC Spirit var4 float %9.0g Buick Century var5 float %9.0g Buick Electra ---------------------------------------------------------------------------------------------------- Sorted by: Note: Dataset has changed since last saved.
It depend on what you want to do next, but you really have no other choice but:
1. To change city names if you want to call variables like the cities.
2. Move the city names to the variable labels.
Originally posted by Konstantina Maragkou
View Post
Comment