Dear Statalisters,

I work on a database in which results of an enterprise survey (multiple choice questions) are collapsed into the sum of options chosen by the respondents within an enterprise. Example: In first row, within firm “A”, 9 respondents chose opt1; 7 chose opt2; and 8 chose opt3.

clear
input str6 firm_id byte (opt1 opt2 opt3)
"A" 9 7 8
"B" 15 5 8
"C" 3 6 3
"D" 4 3 3
"E" 10 6 2

What I need is to disaggregate each total into single records. My code is:
expand opt1 if firm_id=="A"
replace opt1=1 if firm_id=="A"

Maybe there is a better way to do it. Also, I need to create a loop with foreach over 220 variables and 500 enterprises.

Thank you,

Iciar Pavez