Hello,
I am working with data from a recurring, large-scale survey (~50 biweekly datasets, each containing 200-400+ variables, and ~60-80,000 different participants in each dataset). The variables have changed over time - some become obsolete or are replaced, and some are modified to have their values either expanded (to either more or fewer categories), so I want to have them all in one place to track those changes.
To start, I would like to list the variables in each dataset in one excel sheet, but so far have only been able to get them listed into one excel file on (50) individual sheets, using the following code:
I've tried to modify the code to indicate specific cell placement, trying different variations of 'ul_cell', 'lr_cell', and specific cell values (though that didn't work because it wouldn't iteratively move the values over with each loop, and I'm not sure how to do a loop for cell placement).
but got the error message: _CELL invalid row number in cell() option
I've tried to explore options with putexcel, but this seems to require a matrix, and I can't quite figure out how to output the variable list into a matrix (though there are examples of how to do this with regression results or similar, it doesn't seem to work for the variable list). Listtab/Listtab_vars also does not seem to work, but I'm not sure if these commands are not suitable for what I'm trying to do, or if I've just not coded correctly.
If this cannot be done, I can just import the variable lists from the 50 excel sheets into a new stata dataset and export that into excel, or even do it manually (49 copy & pastes!), but it seems like something straightforward that should be possible to code (in anticipation of future additions of data).
Thank you in advance!
I am working with data from a recurring, large-scale survey (~50 biweekly datasets, each containing 200-400+ variables, and ~60-80,000 different participants in each dataset). The variables have changed over time - some become obsolete or are replaced, and some are modified to have their values either expanded (to either more or fewer categories), so I want to have them all in one place to track those changes.
To start, I would like to list the variables in each dataset in one excel sheet, but so far have only been able to get them listed into one excel file on (50) individual sheets, using the following code:
Code:
* adding to individual sheets - the initial code pulls out the variable names, saves as text, then exports variable list to excel. * Based on: https://atcoordinates.info/2022/02/22/creating-stata-variable-lists-in-excel-and-do-files-with-python/ forvalues y = 1(1)50 { cd "/Users/.../CFI_Data/3_Working_Data" use survey_wk_`y', clear describe, short translate @Results check.txt, replace describe, replace sort name export excel position name using survey_wk_1_50_variables.xlsx, firstrow(variables) sheet(Wk`y') clear }
I've tried to modify the code to indicate specific cell placement, trying different variations of 'ul_cell', 'lr_cell', and specific cell values (though that didn't work because it wouldn't iteratively move the values over with each loop, and I'm not sure how to do a loop for cell placement).
Code:
... export excel position name using survey_vars_test7.xlsx, firstrow(variables) sheet(Sheet1, modify) cell(ul_cell)
I've tried to explore options with putexcel, but this seems to require a matrix, and I can't quite figure out how to output the variable list into a matrix (though there are examples of how to do this with regression results or similar, it doesn't seem to work for the variable list). Listtab/Listtab_vars also does not seem to work, but I'm not sure if these commands are not suitable for what I'm trying to do, or if I've just not coded correctly.
If this cannot be done, I can just import the variable lists from the 50 excel sheets into a new stata dataset and export that into excel, or even do it manually (49 copy & pastes!), but it seems like something straightforward that should be possible to code (in anticipation of future additions of data).
Thank you in advance!
Comment