Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: Re: monte carlo on panel data


From   "Joseph Coveney" <[email protected]>
To   <[email protected]>
Subject   st: Re: Re: monte carlo on panel data
Date   Sun, 9 Feb 2014 10:35:31 +0900

Ghazal Zulfiqar wrote:

That helped in the sense that now I dont have to manually open the "results"
file, but it still gives me the problem of just 1000 observations rather than
500,000 i.e. one for each run.

--------------------------------------------------------------------------------

Well, yes, that's what -postfile- does:   its saves a scalar and not a column of
data.  So, when you -post- your result in each pass through the loop, it will
save only the value in the first observation.

Frankly, I don't understand what your simulation is supposed to accomplish--your
algorithm doesn't look like what I do when performing Monte Carlo simulations
involving multilevel / hierarchical / panel models.  Regardless, if you're
interested in getting the half-million predictions, here's the mechanics:
First, use -save- an empty temporary dataset to receive the column of data from
each pass through the loop.  Then, in the loop, -append- and -save , replace-
the temporary dataset so that each five hundred observations cumulates in it.
It will be a bit slow because of all of the I/O.  Try something like that below
to get your 500 000 predictions.

Joseph Coveney

preserve
drop _all
save results, emptyok
restore

set seed 3213799
quietly {
    generate float diversity = .	
    forvalues I = 1/1000 {
        replace diversity = median(conc_diversity)+ runiform()
       regress stddev diversity asia latin_am europe africa_mideast ///
        log_gdp_capita log_gdp_capita_1 log_gdp_capita_2 ///
        pop_g_rate barro_ipol investment_rate t t_sqrd
        predict xb

        preserve
        keep xb
        append using results
        save results, replace
        restore
        drop xb
    }
}

use results, clear
summarize xb

exit


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index