Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exporting dataset to Excel with variables levels stored as words instead of numbers.

    Hi,
    I want to save a dataset in Excel or any other format with the variable levels as words instead of the numeric values. Right now the variable levels (e.g. States) get exported as numbers (1, 2, 3...) but I want them to retain the original levels (e.g. Alabama, Alaska, Arizona...).

    Please let me know if there is a way to do this in Stata 16.

    Thank you.

  • #2
    This is your 235th post. By now you should know that posting your code and/or example data is often required and always helpful for answering questions.

    Anyway, I cannot reproduce your problem. I use

    Code:
    sysuse auto
    export excel using auto.xlsx
    to export the auto.dta dataset that is shipped with Stata. The last variable, foreign, has values 0 and 1; instead, their respective value labels, "Domestic" and "Foreign" are exported as strings, just like you (seem to) ask for. Please show (not explain!) a reproducible example.
    Last edited by daniel klein; 21 Sep 2021, 11:42.

    Comment


    • #3
      Hi Sonnen,

      Make sure you use "label values" command to assign variable levels to the values.
      Export excel command will export variable labels as default (ie: Alabama, Alaska, Arizona...if the "label values" command was excuted).
      You can export variable values only if you choose option no label when using export excel command.

      Check help file for more detail.
      Good luck!

      Comment


      • #4
        Originally posted by daniel klein View Post
        This is your 235th post. By now you should know that posting your code and/or example data is often required and always helpful for answering questions.

        Anyway, I cannot reproduce your problem. I use

        Code:
        sysuse auto
        export excel using auto.xlsx
        to export the auto.dta dataset that is shipped with Stata. The last variable, foreign, has values 0 and 1; instead, their respective value labels, "Domestic" and "Foreign" are exported as strings, just like you (seem to) ask for. Please show (not explain!) a reproducible example.

        This worked! Thank you so much.
        Just out of curiosity, is there a way to this for other formats e.g. sav, sasbdat?

        Comment


        • #5
          See

          Code:
          help export
          for what is available in official Stata.

          Comment

          Working...
          X