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: AW: getting results in simulate with loop


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: getting results in simulate with loop
Date   Tue, 2 Mar 2010 14:21:10 +0100

<> 

Try:


*************

capt prog drop myprog

pr myprog,rclass
	vers 10.1
	drop _all
	set obs 10000
	gen x=rnormal()
	gen y=2+4*x+rnormal()
	
				/*
				begin  -postfile-  
			 */
			
			tempname hdle
			tempfile info
			
			postfile `hdle' number tofx /* 
			*/ using `info'
			
			qui forv i=1/100{
					reg y x if runiform()<.7
					post `hdle' (`i') (_b[x]/_se[x])
			}
			postclose `hdle'
			u `info', clear
			sort tofx
			keep in 1
			
			/*
			 end -postfile-  
			*/

	ret sca min=tofx
	ret sca minnum=number
end

simulate min=r(min) minnum=r(minnum), reps(50): myprog
list, noo h(30)

*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Maximiliano
Méndez Parra
Gesendet: Dienstag, 2. März 2010 13:37
An: [email protected]
Betreff: st: getting results in simulate with loop

Here is my problem.

I am performing a Monte Carlo experiment. Inside each replication (5000) set
by the simulate command, there exists a loop that performs 100 regressions
using different model definitions. The program was designed to choose the
minimum t-stat/F-values  of each of the 100 regressions. Therefore, at the
end, I will have a distribution with 5000 minimum values of t-stat/F-values.


I am interested in knowing for each of the 5000 replication in which of the
100 regressions the minimum t-stat was found. I am evaluating two
alternatives

1.       Get at the end of the simulation for each minimum t and associated
value for the regression in each of the 5000 replications (Do not know how).
This will be ideal but I have tried to capture that using scalars trying to
identify that moment. The problem is that if statements do not work with
scalars.

2.       Save the intermediate results of each of the sets of 100
regressions for later analysis. I am using the postfile command to get the
minimum t-stats/F-stats. The problem is that after running the 5000
simulations, I am getting just the intermediate results of the last
replication. It is replacing the values obtained in the previous. So I only
get the 100 t-stats of the last replication. There is no possibility of
using append in postfiles.

Can anybody help me? Maybe you have an alternative way of doing what I want.
Thanks in advance.

My program looks like this



program seascrit1, rclass

version 10.0

drop _all

tempname sim

postfile `sim' timeb1 results,replace



More commands...



forvalues i=1/100{



More commands...





reg XXX YYY ZZZ TTT....



test YYY TTT

scalar Fa`i'=r(F)

scalar ba`i' = (_coef[YYY])/_se[YYY]

scalar bb`i' = (_coef[l.z2t])/_se[l.z2t]

scalar timeb`i'=_n



post `sim' (tb) (timeb`i') (ba`i') (shift)





}

*end of loop





postclose `sim'



return scalar b1 = min(ba1-ba100)







scalar drop _all



end

simulate  b1=r(b1), reps(5000) : seascrit1


-- 
Maximiliano Méndez Parra
[email protected]

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


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


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