Site icon Stata.Professor : Your Partner in Research

asdoc in a loop with nest option in Stata

Dear Attaullah Shah, good afternoon. I’m a Stata user, but some programming things I do not understand yet. I’ve been looking at forums like https://stackoverflow.com/questions/53524560/looping-and-storing-beta-coefficients-after-regress-over-files#new-answer answer to a question I have. I am not able to make my loop save the results after regressing over files (betas, t, R2 and N), with all my datasets. I have 11 named 2005.dta to 2017.dta (except for 2009) contained in a folder (F:\datasets). The objective is to use asdoc, and to generate a summary table of the estimates I make. The code that I have written is the following.
cd "F: \ datasets"
local i: dir. files "* .dta"
foreach file in `i' {
    asdoc reg and x1 x2 x3, append nest rep (t | se) ///
          title (Table 1 MCO per year) dec (3)
}
But the result is that asdoc saves the results of a single database (only the first – 2005) 11 times and does nothing for the others. If you could have time to help me solve this problem I would thank you very much. Cheers Juan
Exit mobile version