Announcement

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

  • Categorical recode inquiry

    Hello everyone,

    I recoded "race" into "race_cat" which merged the original "race" data which had a lot of attachments. The question I have is how do I go from "race_cat" which has white, black, asian, and other into standalone variables. To clarify, I want to go from "race_cat" into "white" "black" "asian" and "other". Currently the range for "race_cat" is 4.

    Click image for larger version

Name:	Screenshot 2023-04-29 at 5.09.25 PM.png
Views:	1
Size:	484.7 KB
ID:	1711763

    Click image for larger version

Name:	Screenshot 2023-04-29 at 5.11.45 PM.png
Views:	1
Size:	79.6 KB
ID:	1711764

    Click image for larger version

Name:	Screenshot 2023-04-29 at 5.08.45 PM.png
Views:	1
Size:	132.1 KB
ID:	1711765


  • #2
    Why do you want to do that? Unless you are running an archaic version of Stata, there is almost no situation that requires separate variables like that. Use factor-variable notation instead. (See -help fvvarlist- if you are not familiar with it.)

    That said, if for some reason you really do need separate indicator variables for the four race categories:
    Code:
    forvalues i = 1/4 {
        gen byte `=strtoname("`:label (race_cat) `i''")' = `i'.race_cat
    }

    Comment


    • #3
      Cross-posted at https://www.reddit.com/r/stata/comme...code_question/

      Please note our policy on cross-posting, which is that you are asked to tell us about it. https://www.statalist.org/forums/help#crossposting

      r/stata have the same policy -- which they call a rule.

      Comment

      Working...
      X