Statalist


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

Re: st: Stata programming: While Command


From   "Eva Poen" <[email protected]>
To   [email protected]
Subject   Re: st: Stata programming: While Command
Date   Mon, 3 Mar 2008 12:46:13 +0000

Leonor,

there is a better alternative to -while- in this case.
Try the following:

foreach x of varlist ind1 ind2 ind3 ind4 ind5 ind6 ind7 ind8 ind9 {
  regress TAX EXP if `x'==1, robust
  predict tax_hat_`x'
  xtreg INV tax_hat_`x' if `x'==1, fe  vce(bootstrap)
}

Hope this helps,
Eva


2008/3/3, Leonor Saravia <[email protected]>:
> Dear Statalisters,
>
>  I'm learning how to make some programs in Stata, but I�m having
>  problems in using the 'while' command.
>
>  My database looks like this:
>
>  FIRM_ID         IND1   IND2    IND3 .....IND9   TAX      INV
>  120                  1        0         0          0         0.16     100
>  123                  0       1          0          0        0.16      200
>  120                  1        0         0          0         0.15     150
>  134                  0        0         0          1         0.16     180
>  123                  0        1         0          0         0.15     200
>  134                  0        0         0          1         0.15     120
>  .
>  .
>  123                  0        1         0          0         0.17     130
>
>  I need to do a two step regression by the variable IND, this is:  when
>  IND1==1, IND2==1, IND3==1, ...,IND9==1, I need that Stata runs this
>  programm:
>                                                          First step:
>  regress TAX EXP, robust
>
>    predict tax_hat
>                                                          Second step:
>  xtreg INV tax_hat, fe
>                                                                            end
>
>  So, what I was trying to do in my do-file was (and it's not working):
>
>  local industria "ind1 ind2 ind3 ind4 ind5 ind6 ind7 ind8 ind9"
>
>  while `industria' == 1 {
>
>  reg tax exp, robust
>
>  predict double tax_hat
>
>  xtreg ln_inv tax_hat, fe vce(bootstrap)
>
>  drop tax_hat
>
>  }
>
>  But when I do this, Stata gives me this message:     program error:
>  code follows on the same line as open brace
>
>  I don�t understand what�s the problem so I'd appreciate your help very much.
>
>  Thanks,
>
>  Leonor
>
>  *
>  *   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/



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