This should be simple but I can't get it to work. I have a data set attached in which I want to create a variable for US states. The state variables in the World Values Study are X048ISO and X048WVS.I created a variable called region from X048WVS. I then wanted to create a state level variable when X048WVS is not equal to a region value. So I typed and received:
gen str24 state = "."
. des state
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------------------------------------------------------
state str24 %24s
. replace state = X048WVS if region1 == "."
type mismatch
r(109);
where region is gen str24 state = "."
. des state
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------------------------------------------------------
state str24 %24s
. replace state = X048WVS if region1 == "."
type mismatch
r(109);
where region ==
. fre X048WVS if S003 == 840
X048WVS -- Region where the interview was conducted (WVS)
----------------------------------------------------------------------------------------
| Freq. Percent Valid Cum.
-------------------------------------------+--------------------------------------------
Valid -2 No answer | 55 0.62 0.62 0.62
840001 US: New England | 364 4.13 4.13 4.75
840002 US: Middle Atlantic States | 962 10.91 10.91 15.66
840003 US: South Atlantic | 971 11.01 11.01 26.67
840004 US: East South Central | 462 5.24 5.24 31.91
840005 US: West South Central | 670 7.60 7.60 39.51
840006 US: East North Central | 996 11.29 11.29 50.80
840007 US: West North Central | 418 4.74 4.74 55.54
840008 US: Rocky Mountain state | 369 4.18 4.18 59.72
840009 US: Northwest | 156 1.77 1.77 61.49
840010 US: California | 445 5.05 5.05 66.54
840011 US: Alaska | 3 0.03 0.03 66.57
840012 US: Hawai | 4 0.05 0.05 66.62
840013 US: Pacific | 348 3.95 3.95 70.56
840201 US: AL Alabama | 28 0.32 0.32 70.88
840202 US: AR Arkansas | 11 0.12 0.12 71.01
840203 US: AZ Arizona | 73 0.83 0.83 71.83
840204 US: CA California | 282 3.20 3.20 75.03
840205 US: CO Colorado | 73 0.83 0.83 75.86
840206 US: CT Connecticut | 26 0.29 0.29 76.15
: | : : : :
840231 US: NJ New Jersey | 56 0.63 0.63 89.36
840232 US: NM New Mexico | 27 0.31 0.31 89.67
840233 US: NV Nevada | 22 0.25 0.25 89.92
840234 US: NY New York | 118 1.34 1.34 91.26
840235 US: OH Ohio | 101 1.15 1.15 92.40
840236 US: OK Oklahoma | 28 0.32 0.32 92.72
840237 US: OR Oregon | 33 0.37 0.37 93.09
840238 US: PA Pennsylvania | 83 0.94 0.94 94.04
840239 US: RI Rhode Island | 8 0.09 0.09 94.13
840240 US: SC South Carolina | 12 0.14 0.14 94.26
840241 US: SD South Dakota | 24 0.27 0.27 94.53
840242 US: TN Tennessee | 55 0.62 0.62 95.16
840243 US: TX Texas | 177 2.01 2.01 97.17
840244 US: UT Utah | 22 0.25 0.25 97.41
840245 US: VA Virginia | 68 0.77 0.77 98.19
840246 US: VT Vermont | 6 0.07 0.07 98.25
840247 US: WA Washington | 65 0.74 0.74 98.99
840248 US: WI Wisconsin | 68 0.77 0.77 99.76
840249 US: WV West Virginia | 19 0.22 0.22 99.98
840250 US: WY Wyoming | 2 0.02 0.02 100.00
Total | 8819 100.00 100.00
--------------------------------------------------------------------------------------
and I wanted to assign state values of . fre X048WVS if S003 == 840
X048WVS -- Region where the interview was conducted (WVS)
----------------------------------------------------------------------------------------
| Freq. Percent Valid Cum.
-------------------------------------------+--------------------------------------------
Valid -2 No answer | 55 0.62 0.62 0.62
840001 US: New England | 364 4.13 4.13 4.75
840002 US: Middle Atlantic States | 962 10.91 10.91 15.66
840003 US: South Atlantic | 971 11.01 11.01 26.67
840004 US: East South Central | 462 5.24 5.24 31.91
840005 US: West South Central | 670 7.60 7.60 39.51
840006 US: East North Central | 996 11.29 11.29 50.80
840007 US: West North Central | 418 4.74 4.74 55.54
840008 US: Rocky Mountain state | 369 4.18 4.18 59.72
840009 US: Northwest | 156 1.77 1.77 61.49
840010 US: California | 445 5.05 5.05 66.54
840011 US: Alaska | 3 0.03 0.03 66.57
840012 US: Hawai | 4 0.05 0.05 66.62
840013 US: Pacific | 348 3.95 3.95 70.56
840201 US: AL Alabama | 28 0.32 0.32 70.88
840202 US: AR Arkansas | 11 0.12 0.12 71.01
840203 US: AZ Arizona | 73 0.83 0.83 71.83
840204 US: CA California | 282 3.20 3.20 75.03
840205 US: CO Colorado | 73 0.83 0.83 75.86
840206 US: CT Connecticut | 26 0.29 0.29 76.15
: | : : : :
840231 US: NJ New Jersey | 56 0.63 0.63 89.36
840232 US: NM New Mexico | 27 0.31 0.31 89.67
840233 US: NV Nevada | 22 0.25 0.25 89.92
840234 US: NY New York | 118 1.34 1.34 91.26
840235 US: OH Ohio | 101 1.15 1.15 92.40
840236 US: OK Oklahoma | 28 0.32 0.32 92.72
840237 US: OR Oregon | 33 0.37 0.37 93.09
840238 US: PA Pennsylvania | 83 0.94 0.94 94.04
840239 US: RI Rhode Island | 8 0.09 0.09 94.13
840240 US: SC South Carolina | 12 0.14 0.14 94.26
840241 US: SD South Dakota | 24 0.27 0.27 94.53
840242 US: TN Tennessee | 55 0.62 0.62 95.16
840243 US: TX Texas | 177 2.01 2.01 97.17
840244 US: UT Utah | 22 0.25 0.25 97.41
840245 US: VA Virginia | 68 0.77 0.77 98.19
840246 US: VT Vermont | 6 0.07 0.07 98.25
840247 US: WA Washington | 65 0.74 0.74 98.99
840248 US: WI Wisconsin | 68 0.77 0.77 99.76
840249 US: WV West Virginia | 19 0.22 0.22 99.98
840250 US: WY Wyoming | 2 0.02 0.02 100.00
Total | 8819 100.00 100.00
--------------------------------------------------------------------------------------
and I wanted to attach values to state from W048WVS when W048WVS is a state, not a region. But my command didn;t work (see above). I tried to upload the data set (very small) but it wouldn;'t load. But this should be obvious to people who can do this better than I can.
Thanks,
Ric Uslaner
Comment