Convert variable value from two variables into a separate variable value

101 views Asked by At

I have the following data matrix containing Poole dw-nominate scores:

con  statenm    party   name     dwnom1
 80    USA       100    TRUMAN   -.276
 80   ALABAMA    100    BOYKIN F -.026

I was wondering if there was a way in Stata to turn the USA dwnom1 value into a specific variable, USA_dwnom1. I'd like to have each variable with a value of cong == 80 to have the value of -.276 for each value of the new variable of USA_dwnom1.

Once more, I was wondering if there was a way to do this in a loop (I'm doing this from the 80th to the 112th Congress).

1

There are 1 answers

0
dimitriy On BEST ANSWER

There are many ways of doing this. Here's one using a user-written command xfill:

clear

input con  str7 statenm party   str8 name dwnom1
80   USA         100    "TRUMAN"     -.276
80   ALABAMA     100    "BOYKIN F" -.026
end

net from http://www.sealedenvelope.com/
net install xfill

gen USA_dwnom1 = dwnom1 if statenm =="USA"
xfill USA_dwnom1, i(con)   

carryforward is another option. Some other first-principles solutions that use replace and subscripting can be found here.

There's no need to loop over congresses.