Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 72762

Having trouble with STATA overwriting values using replace command

$
0
0
I have a question that I am trying to code "Pick your top 3 favorite colors" Then I have a list
1. Blue
2. Red
3. Green
4. Yellow
5. Brown
etc.

Each of these colors is its own variable and if a student said it was their favorite color the value is coded as a "1" if not it is "0"

My problem is that when I try and combine them into one master "colors" variable the values which were present get overwritten
example:

gen colors=.
replace colors=1 if blue==1
replace colors=2 if red==1
replace colors=3 if green==1
replace colors=4 if yellow==1
replace colors=5 if brown==1

as the code is written if a student picked red green and yellow as their favorite colors in turn red would be overwritten when the replacement for green is made and green would be overwritten when the replacement for yellow is made. How do I stop this from happening?

Viewing all articles
Browse latest Browse all 72762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>