2008/5/15 Ziyang Wang <[email protected]>:
> 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/