Stata - How to use tostring / destring

Поділитися
Вставка
  • Опубліковано 10 гру 2024

КОМЕНТАРІ • 14

  • @kylemccoy1277
    @kylemccoy1277 6 місяців тому

    so helpful!!!

  • @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 🙏🏻

  • @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

  • @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!