I have a dataset for transportation research. I have imported the data into STATA 17. The dataset contains a variable called age (is of string str5) has five categories <18, 18-29, 30-45, 46-60 and >60. The problem is that it is in string, but I need to convert it so that I can use it for regression. I looked into STATA forum and the majority of posts recommended to use encode( ) to make it numeric. After converting it to numeric what I observed that the label encoding (value labels) shuffled say for 18-29: 1, 30-45: 2, 46-60: 3; <18: 4, >60: 5.
Can anyone help me with the code (reproducible for any string variable) that will convert the variable to numeric (so that can be used for regression task) and relabel it (<18: 0, 18-29: 1, 30-45: 2, 46-60: 3 and >60: 4).
Goal: The goal is to convert it to numeric and change the existing value labels to desired custom value labels.
Thanks in advance.
Related Posts with How to convert a string variable to numeric and customize the label encoding?
Assigning dates and days of week in a long datasetHello, I have a long dataset with observations that represent all of the days that a person was enr…
Difference between the two options under model two tab for three stage least squares?In stata after going to statistics-->endogenous covariates ---> Three stage least squares and …
Propensity Score with TEFFECTS / IPWRA: is it possible to create a bar graph showing covariate balancing?In looking through the TEFFECTS help files & PDF manual, I do see that a graph of individual cov…
iterations - stteffects ipwraHello, I am attempting to the stteffects ipwra in order to study the effect of drug1 on time to deat…
Creating summary statistic tables with multiple variables with multiple super-columns.Hi all, I am trying to replicate the results of a paper, and I am having trouble creating nicely fo…
Subscribe to:
Post Comments (Atom)
0 Response to How to convert a string variable to numeric and customize the label encoding?
Post a Comment