I have a name list, and I want to list these names in blocks according to a criterion. Let me use an example to make my question clear.
Code:
sysuse auto gen category=substr(make,1,1)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str1 category str176 make "A" "AMC Concord; AMC Pacer; AMC Spirit; Audi 5000; Audi Fox" "B" "BMW 320i; Buick Century; Buick Electra; Buick LeSabre; Buick Opel; Buick Regal; Buick Riviera; Buick Skylark" "C" "Cad. Deville; Cad. Eldorado; Cad. Seville; Chev. Chevette; Chev. Impala; Chev. Malibu; Chev. Monte Carlo; Chev. Monza; Chev. Nova" "D" "Datsun 200; Datsun 210; Datsun 510; Datsun 810; Dodge Colt; Dodge Diplomat; Dodge Magnum; Dodge St. Regis" "F" "Fiat Strada; Ford Fiesta; Ford Mustang" "L" "Linc. Continental; Linc. Mark V; Linc. Versailles" "M" "Mazda GLC; Merc. Bobcat; Merc. Cougar; Merc. Marquis; Merc. Monarch; Merc. XR-7; Merc. Zephyr" "O" "Olds 98; Olds Cutl Supr; Olds Cutlass; Olds Delta 88; Olds Omega; Olds Starfire; Olds Toronado" "P" "Peugeot 604; Plym. Arrow; Plym. Champ; Plym. Horizon; Plym. Sapporo; Plym. Volare; Pont. Catalina; Pont. Firebird; Pont. Grand Prix; Pont. Le Mans; Pont. Phoenix; Pont. Sunbird" "R" "Renault Le Car" "S" "Subaru" "T" "Toyota Celica; Toyota Corolla; Toyota Corona" "V" "VW Dasher; VW Diesel; VW Rabbit; VW Scirocco; Volvo 260" end
Code:
bysort category: gen count=_N gen make2="" local i=0 while `i'<=12 { bysort category: replace make2=make2[_n]+"; "+make[_n+`i'] local i = `i' + 1 }
0 Response to List values of one variable in blocks
Post a Comment