I have been sent some data in an Excel spreadsheet that is formatted in an unfriendly way for importing to Stata. It uses merged cells to categorise repeating column names, so that a screenshot is, for once, probably the best way to show sample data:

The actual data has many more Groups and 10 variables within each group. My problem is how to keep the grouping and column information when importing each variable into Stata. When I import the data using the options
, Group B's variables become "F", "G" etc. so as not to duplicate the variable names from Group A.
Is there some clever way after the import to generate variable names A_Age, A_Sex, ..., B_Age, B_Sex,...etc? For reference, the .csv of the example data is:
The actual data has many more Groups and 10 variables within each group. My problem is how to keep the grouping and column information when importing each variable into Stata. When I import the data using the options
Code:
cellrange(A2) firstrow
Is there some clever way after the import to generate variable names A_Age, A_Sex, ..., B_Age, B_Sex,...etc? For reference, the .csv of the example data is:
Code:
Group A,,,,,Group B,,,,,Group C,,,, Age,Sex,Fed,Score,Total,Age,Sex,Fed,Score,Total,Age,Sex,Fed,Score,Total 10,M,AUS,5,5,5,F,AUS,5,4,8,M,AUS,2,2
Comment