Announcement

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

  • Converting alphabetic dummy variable into numeric

    Hello Statalists

    I have a variable "inddum", that represents the industry dummy (snapshot is attached) . This variable shows the industry from where firm belongs. Problem is that it is not available in binary form like (0,1), rather it is in alphabetic form (like L,J,N etc). How can I convert this alphabetic form into numeric form ?


    Attached Files

  • #2
    You need to use the encode command.

    Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. Pictures of your data are not as helpful as actual samples created with the dataex command.

    Comment


    • #3
      Just an additional note, after William's wise advice (please, do not forget to take a look at the FAQ). Since inddum is a string variable, you may wish to take a look at - encode - command.

      For example:

      Code:
      . encode inddum, gen(newvar)
      Last edited by Marcos Almeida; 23 Mar 2017, 06:18.
      Best regards,

      Marcos

      Comment


      • #4
        Although I endorse the advice about screenshots (please don't, really please don't), I can just read that industry has several categories, so encode will not produce a binary variable here. In fact, with nothing else said, its values will be integers 1 up, and it won't (can't) be a dummy in the usual sense with values just 0 and 1. .

        That is not a problem really: you just need to learn about factor variable notation.

        Code:
        help fvvarlist
        (We should nor need to point it out but many people here read Statalist on their phones or tablets, so how much do you think they can read? Not everyone is using a monitor as big as a big television.)

        Comment


        • #5
          I interpreted "binary" as, actually, a request for a numeric variable, stored as a number, since there was no mention on wanting a set of binary variables. So another piece of advice is that it's particularly helpful to post a small hand-made example, with just the important variable(s) and a few observations, showing the data before the process and how you expect it to look after the process, following the advice In FAQ #12 and using dataex and CODE delimiters to post the example to Statalist.


          Comment


          • #6
            I assumed that: "binary" was just the use of a wrong term; the variable, being "red" in Stata, shall be string; the last phrase ,"How can I convert this alphabetic form into numeric form?", could be translated by "generating a numeric variable from a string variable".

            As we can see, several assumptions. As well remarked in the previous replies, acting accorging to the FAQ would be the best preventive measure.
            Best regards,

            Marcos

            Comment


            • #7
              Thanks for the advice and guidance

              Comment

              Working...
              X