Hi,
I would like to extract the first number of another variable into a new variable. (And an additional one which contains the first and the second number if there is one)
The existing variable has different length in its values:
e.g.
911
9313
61
521
1
...
I would like to create a new variable containing only the first number from each observation
-> meaning:
9
9
6
5
1
It would be great if anyone had a solution, with which it is not necessary to convert it to a string first (if seen a lot of solutions which do that), because I wanna use it as a numeric variable.
+ another solution which does not work for me (because not all observations have the same length) is this one:
the variable containing the numbers mentioned above is called "ISCO"
gen twodigit_ISCO=int(ISCO/100)
Does anyone have any suggestions?
Thanks in advance!!
Clara
Related Posts with Extracting the first number from a numeric variable into a new variable
In a call to a another do-file: log results from the anotherdo-fileHello, The case is that I am running a do-file and I am logging the session. When this do-file call…
Extracting stringsHi there! I am working on cleaning up some text data, and have a quick question. I have the followi…
Saving regression coefficients from 3 regressions in one same datasetI have the dataset that include further below. I ran the following three regressions on this dataset…
Multiple treatments per observation, difference in differenceHi all, I am investigating the impact of metro station accessibility on housing values. For this, I…
Stata I/O error on save despite ample disk spaceI'm running Stata 15.1 MP/4-core in macOS 10.14.5. I have 32 GB of memory. I'm appending a series o…
Subscribe to:
Post Comments (Atom)
0 Response to Extracting the first number from a numeric variable into a new variable
Post a Comment