Hello there,
The popular formula for selecting the first two/three digits of a numeric variable is to convert it to string and then selecting the first two/three digits, then restringing it like the following.
OR
But, my dataset is almost 10 GB size, so if I convert the industry_code to string it shuts off after a long time which is very frustrating. Is there any other way other than the codes above , I can select the first two/three digits of the numerical variable industry_code from my dataset below ??
The popular formula for selecting the first two/three digits of a numeric variable is to convert it to string and then selecting the first two/three digits, then restringing it like the following.
Code:
tostring industry_code, gen(ind_str) gen industry_2_digit = substr(ind_str, 1, 2)
Code:
gen code = substr(strofreal(industry_code), 1, 2)
Code:
input long industry_code 10 10 10 10 10 10 10 10 102 102 102 102 1021 1021 1021 1021 1028 1028 1028 1028 4849 end
Comment