order - How to keep observations match after value label modified? -


i'm doing basic data processing stuff stata. however, stuck on how keep observations of other variables matching, after modifying variable's value label.

for example, say, have raw dataset follows:

   var1   var2   var3        1000    15   china    500    20     uk     800    10 

the var1 string variable. need convert numeric one. typed

   encode var1, gen(country)    // new variable country numeric 

the variables want future work var2, var3 , country.

when new variable generated, automatically has value label. specific, if click on in column of country, shows 3 in cell on top of column.

   var1   var2   var3  country        1000    15       china    500    20   china     uk     800    10     uk 

so far it's good. mean each row observations match.

however, automatically generated value label not want. need make 1 denote uk, 2 , 3 china. modified by:

     label define country 1 "uk" 2 "us" 3 "china", modify 

as shown below, value labels want. like, click on china gives me 3.

     var1   var2   var3  country          1000    15    china     china    500    20     uk       uk     800    10     

but point is, may notice, order of observations country arranged alphabetically. makes corresponding values of var2 , var3 each country wrong.

that not through. since columns need var2, var3 , country, i'd have each country corresponding values of var2, var3 , customized value labels.

i tried sort, order , couple of commands none gave me result. don't know command should use or there's wrong in earlier work.

using label() option of encode, 1 way:

clear set more off  input /// str10 var1   var2   var3        1000    15   china    500    20   uk       800    10 end  label define lblcountry 1 "uk" 2 "us" 3 "china" encode var1, generate(country) label(lblcountry)  list list, nolabel 

see user-written command sencode (super-encode), can more: ssc describe sencode.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -