Announcement

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

  • Intro to Stata - Creating and Changing Variables UW-Madison Website

    Hi Everyone,

    I'm incredibly novice to using Stata, and I'm having trouble following along with this website tutorial that focuses on creating and changing variables (https://www.ssc.wisc.edu/sscc/pubs/i...tro_stata6.htm).

    I was hoping someone could look at the website and view the second exercise portion that states - Combining the ones and twos makes sense because there are so few of them, but there was no particular need to combine the fours and fives. Create a rep4 variable that combines the ones and twos and renumbers the other categories accordingly (i.e. rep4 should go from one to four)

    Could someone look at that website/exercise and give me an idea of what I should input into the command? Please let me know if you need more information provided, the leading resource I'm using is based on the website.

    I appreciate any help you can provide.
    Joe
    Last edited by Joseph Parsons; 23 Jan 2023, 22:33.

  • #2
    Hi Joseph,

    You might start by looking at the example code already provided:

    Code:
    gen rep3 = 1 if rep78<3
    replace rep3 = 2 if rep78==3
    replace rep3 = 3 if rep78>3 & rep78<.
    The question asks you to generate a new variable called rep4 that combines the first two categories of rep78. The code above collapses a 5 category variable (rep78) into a new three category variable (rep3). Notice as well that the example creates a new variable - really, a new column in a table - in the first line with gen, and systematically fills in certain values in rep3 with the numbers 1, 2, or 3, depending on the corresponding row value in rep78. Your goal is to modify this code to create a new variable called rep4 that combines the first two categories of rep78 into a single category (as above) but leaves categories 3, 4, and 5 separate. You are supposed to use the -replace- command for this, as the -recode- command is introduced in the next section.

    I think I would be doing you a disservice if I just told you the answer, but as a hint, I think you can do this in two lines of code. The first line is only a little different than the example above. It combines the first two catagories of rep71: rep3 equals 1 when rep78 is less than 3 - that is, equal to 1 or 2.

    Code:
    gen rep4 = 1 if rep78<3
    The second line of your solution should replace rep4 with values equal to one less than the value of rep78, but only if the corresponding value of rep78 equal 3, 4, or 5. You should not replace values of rep4 if the corresponding value of rep78 is 1, 2, or missing (.).

    I hope that helps!

    Comment


    • #3
      Thank you Daniel!

      I sincerely appreciate the help. The information and hints you've given me are enough to figure the rest out!

      Best,
      Joe

      Comment

      Working...
      X