PDA

View Full Version : If anyone knows...



MrsEcon
01-30-2012, 07:42 AM
Hello, i have a problem i know how to solve it in excel, but i wonder if i could do the same in stata because i want to have all the commands in a dofile.

I have a variable with this kind of values: 69/4600-5000 or 69/4600 or 69(70)/4600
and an another with this type: 1140-1000

And i want to trasform the one into this: 69, and if has a () then create another column with 70 in.

(So i want to keep only the part before / and spread the value in the parethesis into another variable )

And the other into two variable the one: 1140 and the other 1000.

If anyone could help me i would be very thankful!

bukharin
01-30-2012, 04:45 PM
See the help files for:
substr
strpos
split

Using a combination of the above commands you should be able to achieve these transformations.

MrsEcon
01-30-2012, 05:37 PM
It's difficult :'( can you give me an example? (if you want)

bukharin
01-30-2012, 06:30 PM
clear
input str12 a str9 b
"69/4600-5000" "1140-1000"
"69/4600" "1140-1000"
"69(70)/4600" "1140-1000"
end

split a, parse(/)
drop a2
gen a2=substr(a1, strpos(a1, "("), .)
destring a2, ignore("()") replace
replace a1=substr(a1, 1, strpos(a1, "(") - 1) if !missing(a2)

split b, parse(-)
destring b1 b2, replace

list

MrsEcon
01-31-2012, 02:35 AM
Thank you sooo much!!!!!!
Thank you! :)