Hi all,

First Statalist post and beginner on Stata so thank you for your patience!

I am trying to create a single Excel worksheet which will have one row for every error in our dataset. I'm using Stata version 14.2. I have already created the code to identify errors - probably not the smoothest way, but for each variable (e.g. height), I created a new variable (e.g. heightx) whose value is 1 if an error in that variable is detected. My dataset consists of 3,900 observations, each of which represents a form completed by a participant. (About 2,000 participants have completed anywhere between 1-6 forms). The 2,000 participants are identified by an id variable (rid) and the forms have their own variable (form).

In my example, if the value of heightx = 1 for a given form, I would like to export 4 characteristics (id, facility, visit date and form number) taken from the row this is true from. I've used mkmat to create a matrix of these values, and putexcel to export the results to an Excel worksheet. However, I have hundreds of variables I'll be checking for errors on. Rather than have to export the matrix results each time manually, I was hoping to create a loop (I think using foreach?) and have all the matrix results export at once - stacking vertically within a single Excel worksheet. However, since the number of errors identified in a given variable will constantly be changing (one week there might be 5 errors in heightx, another week 155), I can't predict what row/cell number the second, third and subsequent matrix results will export to.

Is there a way to tell Stata: "export the results of the heightx matrix to Excel and put those in cell A2, and then export the results of the weightx matrix to that same worksheet, beginning at the next blank row"? I did see this post but wasn't quite sure if it's the same thing I'm trying to do...

Thanks for your help,
~Cristina