How To Change String Variable To Numeric In Stata
How to manage variables in STATA?
Data entered in STATA can be classified either as numeric or string blazon. Associated with each type of information is its storage type i.e. the numbers are stored every bit byte, int, long, bladder, or double. STATA takes "float" every bit the default storage type for its variables. Similarly, byte, int, and long are usually used to concur integers. The table given beneath defines the storage type with minimum and maximum value for each variable along with byte size.
Storage Type | Minimum | Maximum | Closest to 0 without beingness 0 | Bytes |
byte | -127 | 100 | +/-1 | 1 |
int | -32767 | 32740 | +/-ane | 2 |
long | -ii,147,483,647 | ii,147,483,620 | +/-ane | 4 |
float | -i.70141173319x x38 | 1.70141173319 x1038 | +/-10-38 | 4 |
double | -8.9884656743×10307 | 8.9884656743 ten 10307 | +/-10-323 | 8 |
In the case of strings, they are stored at str#, i.e. str1, str2, str3………….. str2045 or strL. Here str5 indicates its length.
For example, the male would be str4 (since the discussion 'male' has iv characters) and females would exist str6 (since the word 'female' has 6 characters).
Note that since STATA stores information in the memory, the storage space should exist used judiciously.
For case, the string female with a length of 6 would waste material memory if stored as str20. Similarly, the "byte" size of numeric value would waste matter storage if it is saved as "double".
Converting a string to numeric
Once the information is entered into STATA, it automatically defines the storage type of the data. However, sometimes the variables which have numerical value is taken as a string variable. Since a cord cannot exist used for analysis, it should be converted to numeric.
Check the data set in "Variable Window" (See below), wherein the Name, Label, Type and Format of the variable are defined.
For case: in this case since the var "brand" is registered as str18 and in order to compute it as numeric, it has to exist converted into a numeric.
To convert, employ the command "destring ". This command is used to convert string variables into numeric variables and vice versa. Strings tin can be converted into numeric in two ways.
- Supersede the string variable.
- Create a new variable is numeric.
In order to replace "brand", we will use the command:
destring make, replace
To generate a new var, use the control:
destring make, gen(make1)
where make1 is the new variable in the numeric form.
Other commands which can be used are:
- compress to compress the memory.
- destring to convert cord to numeric and vice a versa.
- format to set output format.
- recast to change storage type.
Working with Variable Manager
On the chief Stata window, click on " variable manager " to manage variables.
A new window will open,
For each variable, the properties are defined on the correct-paw side:
- name,
- label,
- type,
- format,
- value label and
- notes (if any) tin exist added.
In the example of chiselled variables define values past clicking on "Manage".
Click on "Add together Value" to add codes to each sub-category of the variable.
For instance:to add information well-nigh gender, click "Add Value". A new tab will open up to define the value i for Male and 2 for females.
All the same new variables cannot exist added to this window. It can simply be added to the "Information Editor" (Edit) window. Run into the image below for the information editor window:
As shown in the figure higher up, one tin can manage (modified individually) by clicking on "Variable Properties Icon".
How To Change String Variable To Numeric In Stata,
Source: https://www.projectguru.in/variable-management-stata/
Posted by: robbinssencong.blogspot.com
0 Response to "How To Change String Variable To Numeric In Stata"
Post a Comment