Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str17 make int price byte mpg double(rep78 headroom) int(trunk weight length turn) double(displacement gear_ratio) str8 foreign "AMC Concord" 4099 22 3 2.5 11 2930 186 40 121 3.5799999237060547 "Domestic" "AMC Pacer" 4749 17 3 3 11 3350 173 40 258 2.5299999713897705 "Domestic" "AMC Spirit" 3799 22 . 3 12 2640 168 35 121 3.0799999237060547 "Domestic" "Buick Century" 4816 20 3 4.5 16 3250 196 40 196 2.930000066757202 "Domestic" "Buick Electra" 7827 15 4 4 20 4080 222 43 350 2.4100000858306885 "Domestic" "Buick LeSabre" 5788 18 3 4 21 3670 218 43 231 2.7300000190734863 "Domestic" "Buick Opel" 4453 26 . 3 10 2230 170 34 304 2.869999885559082 "Domestic" "Buick Regal" 5189 20 3 2 16 3280 200 42 196 2.930000066757202 "Domestic" "Buick Riviera" 10372 16 3 3.5 17 3880 207 43 231 2.930000066757202 "Domestic" "Buick Skylark" 4082 19 3 3.5 13 3400 200 42 231 3.0799999237060547 "Domestic" "Cad. Deville" 11385 14 3 4 20 4330 221 44 425 2.2799999713897705 "Domestic" "Cad. Eldorado" 14500 14 2 3.5 16 3900 204 43 350 2.190000057220459 "Domestic" "Cad. Seville" 15906 21 3 3 13 4290 204 45 350 2.240000009536743 "Domestic" "Chev. Chevette" 3299 29 3 2.5 9 2110 163 34 231 2.930000066757202 "Domestic" "Chev. Impala" 5705 16 4 4 20 3690 212 43 250 2.559999942779541 "Domestic" "Chev. Malibu" 4504 22 3 3.5 17 3180 193 31 200 2.7300000190734863 "Domestic" "Chev. Monte Carlo" 5104 22 2 2 16 3220 200 41 200 2.7300000190734863 "Domestic" "Chev. Monza" 3667 24 2 2 7 2750 179 40 151 2.7300000190734863 "Domestic" "Chev. Nova" 3955 19 3 3.5 13 3430 197 43 250 2.559999942779541 "Domestic" "Dodge Colt" 3984 30 5 2 8 2120 163 35 98 3.5399999618530273 "Domestic" "Dodge Diplomat" 4010 18 2 4 17 3600 206 46 318 2.4700000286102295 "Domestic" "Dodge Magnum" 5886 16 2 4 17 3600 206 46 318 2.4700000286102295 "Domestic" "Dodge St. Regis" 6342 17 2 4.5 21 3740 220 46 225 2.940000057220459 "Domestic" "Ford Fiesta" 4389 28 4 1.5 9 1800 147 33 98 3.1500000953674316 "Domestic" "Ford Mustang" 4187 21 3 2 10 2650 179 43 140 3.0799999237060547 "Domestic" "Linc. Continental" 11497 12 3 3.5 22 4840 233 51 400 2.4700000286102295 "Domestic" "Linc. Mark V" 13594 12 3 2.5 18 4720 230 48 400 2.4700000286102295 "Domestic" "Linc. Versailles" 13466 14 3 3.5 15 3830 201 41 302 2.4700000286102295 "Domestic" "Merc. Bobcat" 3829 22 4 3 9 2580 169 39 140 2.7300000190734863 "Domestic" "Merc. Cougar" 5379 14 4 3.5 16 4060 221 48 302 2.75 "Domestic" "Merc. Marquis" 6165 15 3 3.5 23 3720 212 44 302 2.259999990463257 "Domestic" "Merc. Monarch" 4516 18 3 3 15 3370 198 41 250 2.430000066757202 "Domestic" "Merc. XR-7" 6303 14 4 3 16 4130 217 45 302 2.75 "Domestic" "Merc. Zephyr" 3291 20 3 3.5 17 2830 195 43 140 3.0799999237060547 "Domestic" "Olds 98" 8814 21 4 4 20 4060 220 43 350 2.4100000858306885 "Domestic" "Olds Cutl Supr" 5172 19 3 2 16 3310 198 42 231 2.930000066757202 "Domestic" "Olds Cutlass" 4733 19 3 4.5 16 3300 198 42 231 2.930000066757202 "Domestic" "Olds Delta 88" 4890 18 4 4 20 3690 218 42 231 2.7300000190734863 "Domestic" "Olds Omega" 19 3 4.5 14 3370 200 43 231 3.0799999237060547 . "NA" "Olds Starfire" 24 1 2 10 2730 180 40 151 2.7300000190734863 . "NA" "Olds Toronado" 10371 16 3 3.5 17 4030 206 43 350 2.4100000858306885 "Domestic" "Plym. Arrow" 4647 28 3 2 11 3260 170 37 156 3.049999952316284 "Domestic" "Plym. Champ" 4425 34 5 2.5 11 1800 157 37 86 2.9700000286102295 "Domestic" "Plym. Horizon" 4482 25 3 4 17 2200 165 36 105 3.369999885559082 "Domestic" "Plym. Sapporo" 6486 26 . 1.5 8 2520 182 38 119 3.5399999618530273 "Domestic" "Plym. Volare" 4060 18 2 5 16 3330 201 44 225 3.2300000190734863 "Domestic" "Pont. Catalina" 5798 18 4 4 20 3700 214 42 231 2.7300000190734863 "Domestic" "Pont. Firebird" 4934 18 1 1.5 7 3470 198 42 231 3.0799999237060547 "Domestic" "Pont. Grand Prix" 5222 19 3 2 16 3210 201 45 231 2.930000066757202 "Domestic" "Pont. Le Mans" 4723 19 3 3.5 17 3200 199 40 231 2.930000066757202 "Domestic" "Pont. Phoenix" 4424 19 . 3.5 13 3420 203 43 231 3.0799999237060547 "Domestic" "Pont. Sunbird" 4172 24 2 2 7 2690 179 41 151 2.7300000190734863 "Domestic" "Audi 5000" 9690 17 5 3 15 2830 189 37 131 3.200000047683716 "Foreign" "Audi Fox" 6295 23 3 2.5 11 2070 174 36 97 3.700000047683716 "Foreign" "BMW 320i" 9735 25 4 2.5 12 2650 177 34 121 3.640000104904175 "Foreign" "Datsun 200" 6229 23 4 1.5 6 2370 170 35 119 3.890000104904175 "Foreign" "Datsun 210" 4589 35 5 2 8 2020 165 32 85 3.700000047683716 "Foreign" "Datsun 510" 5079 24 4 2.5 8 2280 170 34 119 3.5399999618530273 "Foreign" "Datsun 810" 8129 21 4 2.5 8 2750 184 38 146 3.549999952316284 "Foreign" "Fiat Strada" 4296 21 3 2.5 16 2130 161 36 105 3.369999885559082 "Foreign" "Honda Accord" 5799 25 5 3 10 2240 172 36 107 3.049999952316284 "Foreign" "Honda Civic" 4499 28 4 2.5 5 1760 149 34 91 3.299999952316284 "Foreign" "Mazda GLC" 3995 30 4 3.5 11 1980 154 33 86 3.7300000190734863 "Foreign" "Peugeot 604" 12990 14 . 3.5 14 3420 192 38 163 3.5799999237060547 "Foreign" "Renault Le Car" 3895 26 3 3 10 1830 142 34 79 3.7200000286102295 "Foreign" "Subaru" 3798 35 5 2.5 11 2050 164 36 97 3.809999942779541 "Foreign" "Toyota Celica" 5899 18 5 2.5 14 2410 174 36 134 3.059999942779541 "Foreign" "Toyota Corolla" 3748 31 5 3 9 2200 165 35 97 3.2100000381469727 "Foreign" "Toyota Corona" 5719 18 5 2 11 2670 175 36 134 3.049999952316284 "Foreign" "VW Dasher" 7140 23 4 2.5 12 2160 172 36 97 3.740000009536743 "Foreign" "VW Diesel" 5397 41 5 3 15 2040 155 35 90 3.7799999713897705 "Foreign" "VW Rabbit" 4697 25 4 3 15 1930 155 35 89 3.7799999713897705 "Foreign" "VW Scirocco" 6850 25 4 2 16 1990 156 36 97 3.7799999713897705 "Foreign" "Volvo 260" 11995 17 5 2.5 14 3170 193 37 163 2.9800000190734863 "Foreign" end
I have tried with the following code but it replaces the observation with only the value from price.
Code:
unab vlist: price-displacement local nvar: word count `vlist' forval i = 1/`=`nvar'-1' { local thisvar : word `i' of `vlist' local nextvar: word `=`i' + 1' of `vlist' replace `nextvar' = `thisvar' if foreign == "NA" }
0 Response to Move selected observations one variable/column to the right
Post a Comment