Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: AW: getting results in simulate with loop

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




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

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



-----Ursprüngliche Nachricht-----
[] Im Auftrag von Maximiliano
Méndez Parra
Gesendet: Dienstag, 2. März 2010 13:37
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

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

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...


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


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

Maximiliano Méndez Parra

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index