Stata - How to use tostring / destring

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024
  • Welcome to my classroom!
    This video is part of my Stata series. A series where I help you learn how to use Stata. In this video, we look at how to use the tostring/destring command to convert your variables to and from string respectively.
    Note: What I show here is my take on the topic. I would be happy to receive comments!
    Useful links:
    ►Twitch: / steffens_classroom
    ►Twitter: / steff5001
    ►Workpage: www.rug.nl/sta...
    ►Subscribe: cutt.ly/Qfu9cmV

Комментарии • 14

  • @kylemccoy1277
    @kylemccoy1277 3 месяца назад

    so helpful!!!

  • @temitopeoketikun1379
    @temitopeoketikun1379 10 месяцев назад

    I COULD KISS YOU, thank you!

  • @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 года назад +1

      ​@@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.