How to Assign the Values of One Variable to encode Variable in Stata using labmask

How to Assign the Values of One Variable to encode Variable in Stata using labmask.

Do you ever have question about assigning values of one variable to the encode variable.

Please download the sample dataset here

I want to label province name  to the province code. The issue is the province code is string so I cannot applied the label.

I encode the province code into numeric and the applied the province name to province code.

Stata cannot applied the values from other variable. But there is a command written by user can do it. That's it "labmask". You need to install this command.

ssc install labmask

Now it's time to assign values to encode variable.

In dataset "Province_code.dta" there are four variables.

Describe Result in Stata
I encode the variable province_code to new variable name province.

encode province_code, gen(province)

encode in Stata

Then I assign the province name from variable province_name to the new variable province.

labmask province, values(province_name)

label values using labmask in Stata

May be you will criticize that why don't encode with province_name variable?
In Stata if you encode variable contains alphabet it will generate the numeric base on the alphabet sorting ascending. You may not get the code that you need. That's why you need to encode with province_code and assign values from province_name.
 
Now it's your time to do with district code and district name.
Have a good day.

Comments