Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: st: Re: How to run loops with outreg (was st: How to regress and outreg byyear?)


From   "Eva Poen" <eva.poen@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: st: Re: How to run loops with outreg (was st: How to regress and outreg byyear?)
Date   Fri, 16 May 2008 11:40:14 +0100

2008/5/15 Ziyang Wang <wzmartin@ust.hk>:
> I see this solution, but not so sure how does the following two lines work:
>  outreg using myfiles, `append'
>     local append "append"

All it does is that, for the first run of the loop, the command reads
- outreg using myfiles, -
I.e., the macro `append' is empty.

For the second and the following runs, it reads
- outreg using myfiles, append -

This little trick gets round the problem that in the very beginning,
there is nothing to append to, and - outreg ...., append- would lead
to an error message.

If you want to use -replace- the first time round, you would have to
introduce a counter, I think, and branch with an -if- command, along
these lines:

local count 0
foreach var in `r(levels)' {
     local ++count
     xi: areg price mpg turn i.rep if year==`var', absorb(id)
     if `count' == 1{
          outreg using myfiles, replace
     }
     else {
         outreg using myfiles, append
     }
}

Note that in this case you don't need the `append' trick any longer,
since you have to branch anyway. Maybe someone else can come up with
something shorter than this.

Eva
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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