Stata - How to use tostring / destring

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น • 14

  • @kylemccoy1277
    @kylemccoy1277 5 หลายเดือนก่อน

    so helpful!!!

  • @oyku7197
    @oyku7197 2 ปีที่แล้ว +1

    Thank you so much for the video. My problem is that Stata reads comma (which I used as a decimal place separator) as string. When I destring variable, replace force , it just turns it into byte and the byte is just a dot. My number disappears. I do not understand how I can make Stata read my number with decimal places, as a numeric value. How can this be solved? Many thanks

    • @SteffensClassroom
      @SteffensClassroom  2 ปีที่แล้ว

      Hello! Thank you for your comment. Did you try the dpcomma option in the destring command? --> destring varlist, dpcomma
      If you have commas as thousand separators, this could also help: destring var, replace ignore(",") force
      Hope this helps!

    • @oyku7197
      @oyku7197 2 ปีที่แล้ว +2

      ​@@SteffensClassroom I did but in the end 'destring varlist, dpcomma replace'' worked. Thank you so much for replying. You have no idea how straightforward and useful your videos have been for someone who has just started using this program

  • @MrsCuriosityful
    @MrsCuriosityful 2 ปีที่แล้ว +1

    Thank you for the video. I have tried to tostring a variable using both tostring varlist, replace and tostring varlist, gen(new varlist) but both failed. It said "variable cannot be converted reversibly; no replace/ generate". FYI, my numeric variable is 16 digits. How can i solve this? Thank you in advance

    • @SteffensClassroom
      @SteffensClassroom  2 ปีที่แล้ว +1

      I believe you can find a solution here:
      www.statalist.org/forums/forum/general-stata-discussion/general/1310789-cannot-be-converted-reversibly-no-replace
      Hope this helps!

    • @MrsCuriosityful
      @MrsCuriosityful 2 ปีที่แล้ว

      @@SteffensClassroom thank you. I'll look into it 🙏🏻

  • @joshuablank3634
    @joshuablank3634 3 ปีที่แล้ว +1

    what if i get this error: variable_xy cannot be converted reversibly; no replace ?

    • @SteffensClassroom
      @SteffensClassroom  3 ปีที่แล้ว

      Yes indeed. I solved it with no replace.
      Did it work for you?
      Remember, you can also use the option to give your newly converted variable a specific name rather than replacing the existing one. See the options :)

    • @joshuablank3634
      @joshuablank3634 3 ปีที่แล้ว +1

      these two didnt work but ive found something else. if numeric number is larger than 11 digits it doesnt work the easy way to return to string, which was my problem

    • @SteffensClassroom
      @SteffensClassroom  3 ปีที่แล้ว

      Thanks for getting back on it! Happy it worked out

  • @virginiawango3968
    @virginiawango3968 2 ปีที่แล้ว

    i want to convert a variable that is numeric to a string but the variable is numeric because it is labelled and not because it is stored as a numeric. So say variable X is labelled x where in x, 0 "No" 1 "Yes" Now I want X to be a string but stata keeps changing the label values 0 and 1 into a string and not No and Yes. Any help?
    For example, in your example dataset, convert the variable foreign into a string so that now foreign is in red.

    • @SteffensClassroom
      @SteffensClassroom  2 ปีที่แล้ว +1

      Hi Virginia,
      I think I see what you mean. The problem is that Stata does not let you label a string variable. So if you convert a numeric to a string, you lose the values labels that was assigned. Instead you can use the replace command if you want to change it.

  • @temitopeoketikun1379
    @temitopeoketikun1379 ปีที่แล้ว

    I COULD KISS YOU, thank you!