Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: error in custom lincom prog


From   [email protected] (Brian P. Poi, StataCorp)
To   [email protected]
Subject   Re: st: error in custom lincom prog
Date   Sun, 05 Oct 2003 10:27:33 -0500

On 2003-10-03, Alex ([email protected]) wrote:

> Dear Statalisters,

> I am trying to make linear combinations of variables after a regression.  
> I need to save the estimated linear combs and the variance matrix for later
> hypothesis testing, so I can't just use lincom - it doesn't save results 
> in enough detail.

> I don't understand what is wrong with this code:

> /* program snippet for manual lincom */
> #delimit ;
> capture program drop coefdiff;
> program define coefdiff;
>   args prefix yst yend;

>   constraint drop _all;
>   local count=0;
>   for each y of numlist `yst' / `yend' {;
>     local count = `count' + 1;

>     if `y' == 1984 {;

<rest of code omitted>


I think the problem is that the line

   for each y of numlist `yst' / `yend' {;
   
should instead read

   foreach y of numlist `yst' / `yend' {;

Notice there is no space between "for" and "each".  Alex is using the
syntax for the -foreach- statement, but because there is a space between
"for" and "each" in his code, Stata is parsing the syntax as if it were
the older -for- command.


   -- Brian
      [email protected]
*
*   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