Nick,
I did try it with
if `l' == 2
So now the code reads
------------------------------------------
local fname3 "c:\data95\hhineqvar95"
local fname2 "c:\data90\hhineqvar90"
local fname1 "c:\data85\hhineqvar85"
local l=1
while `l'<=3 {
drop _all
use `fname`l'', clear
regress lx1 sqrtw1 h_dage1 h_male1 m_adults1 f_adults1 child1 SL_Tamil1 Moor1 other1 hhsize1 second11 second21 GCE_OL1 GCE_AL1 university1 unemployed1 govt1 private1 employer1 self1 managerial1 clerical1 service1 farmers1 product1 lpaddpc1 lhilpc1 lwage_y1 lremabr_y1 lagri_y1 vehicle1 electri1 phone1 Col1 Gam1 Kal1 Kan1 Mtl1 NE1 Mat1 Kur1 Pol1 Mon1 Rat1 ,noconstant
if `l'<2{
outreg using ineqdec.out, se bdec(2,5,2) bracket noaster ctitle("1985") title ("Decomposition of inequality by individual regressor") replace
}
if `l'==2{
outreg using ineqdec.out, se bdec(2,5,2) bracket noaster ctitle("1990") append
}
if `l'==3 {
outreg using ineqdec.out, se bdec(2,5,2) bracket noaster ctitle("1995") append
}
:
:
:
etc.
-------------------------------------------------
Again, it runs right through once, outputs second regression, but stalls at outreg within outreg app.file.
Here's the trace on output which immediately precedes the error message.
-------------------------- begin outreg.appfile ---
- version 6.0
- syntax using/, varname(string) coefcol(string)
- tempname vord1 vord2 vartmp varsml v2plus vorder merge2
- tempfile tmpf1
- gen str80 `vartmp' = substr(`varname',1,79)
= gen str80 __00000C = substr(__000005,1,79)
- replace `vartmp' = "0" if _n==1
= replace __00000C = "0" if _n==1
- gen str10 `varsml' = trim(`vartmp')
= gen str10 __00000D = trim(__00000C)
- replace `vartmp' = `vartmp'[_n-1]+"!" if `varsml'==""
= replace __00000C = __00000C[_n-1]+"!" if __00000D==""
- count if (`varsml'=="" | (`varsml'[_n+1]=="" & _n!=_N))
= count if (__00000D=="" | (__00000D[_n+1]=="" & _n!=_N))
- local ncoeff2 = r(N)
- local N2 = _N
- gen `vord2' = _n
= gen __00000B = _n
- sort `vartmp'
= sort __00000C
- keep `varname' `coefcol' `vartmp' `vord2'
= keep __000005 __000006 __00000C __00000B
- save "`tmpf1'", replace
= save "C:\Documents and Settings\user\Local Settings\Temp\ST_0200000i.tmp"
> , replace
- if index("`using'", ".")==0 {local using = "`using'"+".out"}
= if index("ineqdec.out", ".")==0 {local using = "ineqdec.out"+".out"}
- insheet using `using', nonames clear
= insheet using ineqdec.out, nonames clear
- describe, short
- local numcol = r(k)
- gen str80 `vartmp' = substr(v1,1,79)
= gen str80 __00000C = substr(v1,1,79)
- local titlrow = (v1[1]!="")
- if `titlrow' {
= if 1 {
- while v1[`titlrow'+1]!="" {
= while v1[1+1]!="" {
local titlrow = `titlrow'+1
}
- }
- local frstrow = 1 + `titlrow'
= local frstrow = 1 + 1
- replace `vartmp' = "0" if _n==`frstrow' & v2=="(1)"
= replace __00000C = "0" if _n==2 & v2=="(1)"
- replace `vartmp' = "0!" if _n==`frstrow' & v2!="(1)"
= replace __00000C = "0!" if _n==2 & v2!="(1)"
- replace `vartmp' = `vartmp'[_n-1]+"!" if `vartmp'==""
= replace __00000C = __00000C[_n-1]+"!" if __00000C==""
- gen long `vord1' = _n
= gen long __00000A = _n
- gen str80 `v2plus' = trim(v2)
= gen str80 __00000E = trim(v2)
- local col = 3
- if `col'<=`numcol' {
= if 3<=2 {
replace `v2plus' = `v2plus' + trim(v`col')
local col = `col'+1
}
- count if ((v1==""&`v2plus'!="") | (v1[_n+1]=="" & (`v2plus'[_n+1]!=""|_n=
> =1) & _n!=_N))
= count if ((v1==""&__00000E!="") | (v1[_n+1]=="" & (__00000E[_n+1]!=""|_n=
> =1) & _n!=_N))
- local ncoeff1 = r(N)
- gen str10 `varsml' = `vartmp'
= gen str10 __00000D = __00000C
- summ `vord1' if `vord1'>`ncoeff1' & `v2plus'!=""
= summ __00000A if __00000A>90 & __00000E!=""
- local endsta1 = r(max)
- if `endsta1'==. {local endsta1 = `ncoeff1'}
= if 92==. {local endsta1 = 90}
- drop `varsml'
= drop __00000D
- sort `vartmp'
= sort __00000C
- merge `vartmp' using `tmpf1'
= merge __00000C using C:\Documents and Settings\user\Local Settings\Temp\S
> T_0200000i.tmp
invalid 'and'
---------------------------------------------------- end outreg.appfile ---
*****************************
I'm so sorry for the bother,
Cheers,
Ramani
Nick Cox <[email protected]> wrote:
> if `l' == 2
>
> is the way to test for equality with 2.
>
> Does this stop _inside_ -outreg-?
>
> Nick
> [email protected]
>
> Ramani Gunatilaka
>
> > Sorry to come up with yet another query so soon after my
> > last. But I am stuck.
> > I am running regression-based decompositions of consumption
> > for three survey years. I want to use outreg so the output
> > is formatted nicely. Here is part of my code.
> >
> > local fname3 "c:\data95\hhineqvar95"
> > local fname2 "c:\data90\hhineqvar90"
> > local fname1 "c:\data85\hhineqvar85"
> > local l=1
> > while `l'<=3 {
> > drop _all
> > use `fname`l'', clear
> > regress y var1 var2 var3 etc.
> > if `l'<2{
> > outreg using ineqdec.out, se bdec(2,5,2) bracket
> > noaster ctitle("1985") title ("Decomposition of inequality
> > by individual regressor") replace
> > }
> > if `l'>1 & `l'<3{
> > outreg using ineqdec.out, se bdec(2,5,2) bracket
> > noaster ctitle("1990") append
> > }
> > if `l'>2 {
> > outreg using ineqdec.out, se bdec(2,5,2) bracket
> > noaster ctitle("1995") append
> > }
> >
> > Thereafter the code goes on to
> > save Beta coefficients of the regression
> > Multiply the variables by the Betas
> > regress those variables on y, and
> > save those Betas.
> > I will spare you those details.
> >
> > My problem is that the loop runs once right through,
> > producing the expected output, then it produces the
> > regression output for the second run (1990), but gets stuck
> > somewhere at the second outreg. I set trace on, too, but
> > couldn't figure out what went wrong.
> > The message I get when the whole thing stalls is,
> >
> > invalid 'and'
> > r(198);
> >
> >
> > I suspect something is wrong with my if statement. I
> > replaced the second with - if `l'=2{ -
> > but that didn't work either.
> > Would anybody have any ideas?
> > Thanks so much,
> > Ramani
> > *
> > * 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/
> *
> * 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/
*
* 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/