+ Reply to Thread
Results 1 to 5 of 5

Thread: If anyone knows...

  1. #1
    Points: 551, Level: 11
    Level completed: 2%, Points required for next Level: 49

    Posts
    24
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Change the type of values in Stata



    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!
    Last edited by MrsEcon; 01-30-2012 at 09:33 AM.

  2. #2
    RoboStataRaptor
    Points: 7,402, Level: 57
    Level completed: 26%, Points required for next Level: 148
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,026
    Thanks
    9
    Thanked 243 Times in 236 Posts

    Re: If anyone knows...

    See the help files for:
    substr
    strpos
    split

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

  3. The Following User Says Thank You to bukharin For This Useful Post:

    MrsEcon (01-30-2012)

  4. #3
    Points: 551, Level: 11
    Level completed: 2%, Points required for next Level: 49

    Posts
    24
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Re: If anyone knows...

    It's difficult :'( can you give me an example? (if you want)

  5. #4
    RoboStataRaptor
    Points: 7,402, Level: 57
    Level completed: 26%, Points required for next Level: 148
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,026
    Thanks
    9
    Thanked 243 Times in 236 Posts

    Re: If anyone knows...

    Code: 
    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

  6. The Following User Says Thank You to bukharin For This Useful Post:

    MrsEcon (01-31-2012)

  7. #5
    Points: 551, Level: 11
    Level completed: 2%, Points required for next Level: 49

    Posts
    24
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Re: If anyone knows...


    Thank you sooo much!!!!!!
    Thank you!

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats