Statalist


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

st: AW: Locals inside of a forvalue loop


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Locals inside of a forvalue loop
Date   Tue, 18 Aug 2009 09:40:18 +0200

<> 

You could of course treat the first round separately, outside the loop. If
you insist on it, here is code that works for me:


*************
clear*
set obs 10000
gen x=  rnormal()  //   runiform()
gen y= 1+2*x+rnormal()
save file1, replace

clear*
set obs 10000
gen x=  rnormal()  //   runiform()
gen y= 0.5+3*x+rnormal()
save file2, replace

clear*
set obs 10000
gen x=  rnormal()  //   runiform()
gen y= 4+x+rnormal()
save file3, replace


local action1 replace
local action2 append
local action3 append

local correlation1  /* 
 */ "description of how the variables are correlated"
local correlation2 /* 
 */ "description of how the variables are correlated using data set 2"
local correlation3 "etc"


capt erase mytable1.txt
capt erase mytable2.txt
capt erase mytable3.txt

forv i=1/3{
 use file`i', clear
 reg y x
 mat A=e(b)
 di "`action`i''"
 mat2txt, matrix(A) saving(mytable) `action`i'' /* 
 */ title(Table 1.`i' Bias and Root Mean Square Errors /* 
 */ when the data is created with `correlation`i'') 
}

!start mytable.txt

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



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Conor Sontag
Gesendet: Dienstag, 18. August 2009 07:57
An: [email protected]
Betreff: st: Locals inside of a forvalue loop

Dear Statalist,

I am working with three data sets that are created using very similar
situations, but are not exactly the same.  What I am trying to do is
the following:

I want to insheet the data sets one at a time:

forvalues i = 1/3{
insheet file`i'..... comma, clear
run a few regressions and store the results
mat2txt, matrix(biasrmse) saving(bias81609.xls) title(Table 1.`i' Bias
and Root Mean Square Errors when the data is created with
`correlation`i'') `action`i''
}

The problem I am having is getting my locals to pass into the mat2txt
command.

Now, before starting the loop, I created the following local variables:
local correlation1 = `"description of how the variables are correlated"'
local correlation2 `"description of how the variables are correlated
using data set 2"'
local correlation3 `"etc"'

I also created locals:
local action1 `"replace" '
local action2 = `"append"'
local action3 = `"append" '

What is my objective?

I wish to replace the table I am creating each time I run the file,
but I want the file to be appended the second and third time that it
runs through the loop.  Thanks!
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index