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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: AW: AW: Locals inside of a forvalue loop |

Date |
Tue, 18 Aug 2009 09:43:27 +0200 |

<> Drop the ************* capt erase mytable1.txt capt erase mytable2.txt capt erase mytable3.txt ************* and the "// runiform()" which do not have a bearing on the outcome... HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss Gesendet: Dienstag, 18. August 2009 09:40 An: statalist@hsphsun2.harvard.edu Betreff: st: AW: Locals inside of a forvalue loop <> 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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Conor Sontag Gesendet: Dienstag, 18. August 2009 07:57 An: statalist@hsphsun2.harvard.edu 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/ * * 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/

**References**:**st: Locals inside of a forvalue loop***From:*Conor Sontag <sontag@sas.upenn.edu>

**st: AW: Locals inside of a forvalue loop***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**st: AW: Locals inside of a forvalue loop** - Next by Date:
**st: AW: Poisson and negative binomial regression** - Previous by thread:
**st: AW: Locals inside of a forvalue loop** - Next by thread:
**st: Poisson and negative binomial regression** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |