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
post and postfile help after regressionI am running a simple regression repeated for ~1,000 variables in a loop. I would like to capture th…
Question about "spxtregress, re sarpanel" and serial correlationRecently saw this tweet from Jeffrey Wooldridge and it made me question my understanding of how spxt…
Dropping unnecessary variable from BRFSS data to save spaceIs there any efficient way to keep the variables I need and drop all the unnecessary variables ? In …
Converting Stata version 16 to Stata version 12 with Stat/Transfer in LinuxDear Forum Members, I have some Stata version 16 data files, which I would like to convert to Stata…
Exact matching on Propensity Score MatchingDear Stata Forum, I’m trying to perform a Propensity Score Matching with exact matching but found m…
Subscribe to:
Post Comments (Atom)
0 Response to Extracting the first number from a numeric variable into a new variable
Post a Comment