I've spent the last 3 hours trying to extract various parts of this string variable <mcaseID> - a concatenated variable.
It is supposed to be a 15 character variable. Given variations in the length of the various components of the caseid variable, leading spaces are padded to make up the length of the variable.
Below are examples of mcaseid values
02070014 02
04960020 03
38228 2
as well as an example of data extract
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str15 mcaseid int mv001 byte(mv002 mv003)
" 32923 10" 329 23 10
" 32925 1" 329 25 1
" 32925 2" 329 25 2
" 330 1 1" 330 1 1
" 330 5 1" 330 5 1
" 330 5 4" 330 5 4
" 330 5 5" 330 5 5
" 330 5 7" 330 5 7
end
With the padded zeros, the mcaseid is a concatenation of 3 separate constituent variables:
mv001 = first 8 digits
mv002= next 4 digits
mv003= final 3 digits/characters
Now, I want to extract these v1, v2, v3 variables. I have tried various commands to no avail.
Code:
gen mcaseid2=mcaseid . destring mcaseid2, gen(mcaseidn) mcaseid2: contains nonnumeric characters; no generate . nsplit mcaseid2, digits(8 4 3) gen(v1 v2 v3) string variables not allowed in varlist; mcaseid2 is a string variable r(109); . destring mcaseid2, gen(mcaseidn) caseid2: contains nonnumeric characters; no generate . gen mcaseidn = real(mcaseid2) (395,286 missing values generated) gen caseidn=mod(mcaseid, 10000) type mismatch
So I am totally lost.... i would very much appreciate some assistance.
Thanks - cY
0 Response to Extracting Parts of a Sting variable: Numerous Attempts failed
Post a Comment