Hi guys,

I would like to perform a regression within a loop and store the results in excel. Ideally the results should look like the file attached.
The problem is that I reached the attached file using estate and estate commands which I know have the problem of not storing more than 300 iteration results.

In particular the code I am using looks as follows:

Code:
forvalues i = 5(1)67{
    forvalues n = 1(1)30{
    use "/Users/federiconutarelli/Dropbox/Federico/data_atc3_new.dta", clear 
        *set seed 1234
        bysort idatc3 (Year): gen byte panelsize = _N
        quietly sum panelsize
        quietly drop if panelsize < r(max)
        quietly drop if atc3no == "D10B" | atc3no == "J6E"|atc3no == "V3C"| atc3no == "V3G"|atc3no == "B1X"|atc3no == "B2F"
        quietly drop idatc3 
        egen idatc3 = group(atc3no) 

        xtset idatc3 Year, noquery


        quietly gen ln_sales = ln(sales)
        quietly gen ln_sales_lag = ln(L.sales)
        quietly gen ln_sales_fwd = ln(F.sales)

    
        quietly randomselect if nrecalls, gen(selected1) n(`i')
        quietly replace nrecalls = 0 if selected1


        quietly gen recalls_normalized = (nrecalls/nprod)*100  
        quietly gen y = ln(salesmnf)

        quietly gen avg_prd_sq = (average_age_prodbyatc3)^2
        quietly gen mean_agefirm_squared = (mean_agefirm)^2
        quietly gen lag_recalls_normalized = L.recalls_normalized
        quietly gen lag2_recalls_normalized = L2.recalls_normalized

        eststo clear
        quietly eststo:  xtreg y recalls_normalized lag_recalls_normalized lag2_recalls_normalized avg_prd_sq mean_agefirm_byatc mean_agefirm_squared hhi share_generics i.Year average_age_prodbyatc3, fe vce(cluster idatc3)
    
        esttab, drop(*Year _cons)
        quietly gen t_c = (_b[recalls_normalized]/_se[recalls_normalized])
        quietly gen t_l = (_b[lag_recalls_normalized]/_se[lag_recalls_normalized])
        quietly gen t_l2 = (_b[lag2_recalls_normalized]/_se[lag2_recalls_normalized])
        **t è significant if it is greater than the absolute value of 1.96
        local t_stats  t_c[1] t_l[1] t_l2[1] 
        local t_stats  t_c[1] t_l[1]
        foreach t in `t_stats'{
            if abs(`t') > 1.96{
                *quietly count if nrecalls
                *local VarLocal = 69-`r(N)'
                display as err  "Setting `i' recalls to 0, `t' becomes significant at the `t'th iteration " 
                estimates store est_`i'_`n'
                local for_outreg `for_outreg' est_`i'_`n'
            }
        }
    }
}

label var recalls_normalized "Current recalls"
label var avg_prd_sq "average prod. square"
label var mean_agefirm_byatc "mean agefirm by atc"
label var hhi "hhi"
label var share_generics_1 "share of generic preoducts"
label var lag_recalls_normalized "Recalls lagged once"
label var lag2_recalls_normalized "Recalls lagged twice"

eststo clear
foreach i of var recalls_normalized lag_recalls_normalized lag2_recalls_normalized avg_prd_sq mean_agefirm_byatc mean_agefirm_squared hhi share_generics {
esttab `for_outreg' using "/Users/federiconutarelli/Desktop/sign_estimates.csv", replace cells("b(fmt(4) star) p( par({ }) fmt(4))")  mtitle("") nonumber noobs drop(*Year _cons)
}
Now I am wondering how to replicate the latter code with postfile so that I can have a .dta that can easily export to excel. I guess that I should define a memvold at the beginning of the loop but then I am lost about how to define a local storing all the coefficients and all the p- values and put them in columns as in the csv file attached.

Thank you