Announcement

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

  • ​Recoding with conditional statements in STATA.

    Sorry if this is a repost but I have looked extensively and i cant figure out how to write out the command i need.

    Basically, I have am looking at arrests and I have CensusTract variable that has values from 1-27 that correspond to to different census neighborhoods the crime occurred in. I want to analyze these arrests based on the neighborhood characteristics of where they occurred. I created variables for Percent Black, Percent unemployed, Percent bachelors degree etc. I need to apply the characteristics of each census neighborhood to the variables I created.

    I attempted the following with no luck.

    recode PercentBlack= .78 if CensusTract==2

    Also, if there is a way to recode all at once so i could just do one command for each of the 27 neighborhood. Something like "if census tract = 3 then PercentBlack = .88, PercentUnemployed=.55, PercentBachelors=.22" that would be even better.

    Thanks for any advice.

  • #2
    Why not create a dataset with the values for each neighborhood? Then merge to your original data using CensusTract as the id variable for the merge. (This will probably be a m:1 merge. Type help merge for more information on that)

    Comment


    • #3
      Thank you!

      Comment


      • #4
        Apart from Sarah's good advice: You try to use recode where you should use the replace command. Also, you can only make one replacement with a replace command.

        Code:
        replace PercentBlack= .78 if CensusTract==2

        Comment

        Working...
        X