Announcement

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

  • Recoding variables with conditional statements

    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
    Try:

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

    Comment


    • #3
      It's not clear why luck should play a part here. The recode command is for changing an existing variable by remapping its values, e.g. by mapping 1 and 2 to 1, 3 and 4 to 2 and 5 to 3. It sounds as if your situation is quite different: you have new data from somewhere which you just need to enter as new variables (new columns, if you like) in the most convenient manner. The new variables could be entered by hand, by copy and paste or by a merge with an existing Stata dataset.

      There is no advantage in any extremely compressed command for data entry if it makes that entry more difficult to check.

      Please note our request that members use full real names.
      Last edited by Nick Cox; 02 Oct 2014, 14:08.

      Comment

      Working...
      X