Announcement

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

  • Generating a string variable with numbers

    Hi all,

    I'm running into some data conversion issues and I'm hoping to get some guidance. Currently, I have a variable from the National Survey for Families and Households (NSFH) that is coded numerically. I am attempting to merge this data set by occupation using the ONET Database due to the SOC codes. The SOC codes are written as 11-1031.00, 33-9099.00, etc. When I generate a "job" variable to replace the NSFH variable, the resulting output is the answer what Stata believes is an equation. Thus, my variable values become negative. How do I generate the "job" variable to be a string so that Stata doesn't calculate the perceived equation? I'm attaching my syntax as well as the output below for your review:
    https://drive.google.com/file/d/1piLh3FxOxH8McLWesh9hANFRoM9Kb_oJ/view?usp=drive_link
    https://drive.google.com/file/d/1KUyJeVHP6bs5XtX8Pyp3OPI0rA07iTfZ/view?usp=drive_link


    Any help to make my new "job" variable a string variable so I can merge my data sets would be greatly appreciated!
    Attached Files

  • #2
    Code:
    gen job = "11-1031.00" if M540A == 3
    replace job = "11-1011.00" if M540A == 4
    //  ETC.
    You need to hold the job variable as a string. Note also that M540A, which is apparently a numeric variable, although you can display it with leading zeroes in Stata if you wish, is more easily referred to without the leading zeroes, as shown.

    Comment


    • #3
      Thank you! This fixed my issue

      If I would like to create a variable that is a cross between two variables, say Race and Employment, how would I go about doing that? Please let me know if you require more information, and I'll do my best to provide the code or examples here.

      Comment


      • #4
        Code:
        egen wanted = group(Race Employment), label

        Comment


        • #5
          See also https://www.stata-journal.com/articl...article=dm0034

          Comment


          • #6
            Originally posted by Clyde Schechter View Post
            Code:
            egen wanted = group(Race Employment), label
            Unfortunately, I receive an error stating "varlist not allowed"
            I am seeing that when I created the '"job" variable as directed above, it does not yield any observations. When I do "sum job," it states that no observations are present. However, when I tabulate job, I receive a total of 6, 857. Can you enlighten me on the disconnect and how I may resolve it so that I may do the quoted code?

            Comment

            Working...
            X