Statalist The Stata Listserver


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

Re: st: Re: syntax error using summarize command inside a macro


From   smerryman@kc.rr.com
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: syntax error using summarize command inside a macro
Date   Thu, 14 Sep 2006 13:08:39 -0500

-set trace on- would reveal this error.  For example:

. sysuse auto,clear
(1978 Automobile Data)

. set tracedepth 1

. set trace on

. local v1 "mpg gear"

.  local samp1 "if fore==0"  

.  foreach v of varlist `v1'  {
  2.  sum `v' if `samp1' 
  3.  }
- foreach v of varlist `v1' {
= foreach v of varlist mpg gear {
- sum `v' if `samp1'
= sum mpg if if fore==0
if not found
  }
r(111);

Also, in your -sum- statement should it not be -sum `v'- not -sum `v1'-
 ?

Scott

----- Original Message -----
From: Michael Blasnik <michael.blasnik@verizon.net>
Date: Thursday, September 14, 2006 1:00 pm
Subject: st: Re: syntax error using summarize command inside a macro
To: statalist@hsphsun2.harvard.edu

> You have the if in the command and also in the macro so that Stata 
> sees "if 
> if"
> 
> M Blasnik
> 
> ----- Original Message ----- 
> From: "Marcella Sapun" <msapun@jhu.edu>
> To: <statalist@hsphsun2.harvard.edu>
> Sent: Thursday, September 14, 2006 1:33 PM
> Subject: st: syntax error using summarize command inside a macro
> 
> 
> > Hi there,
> >
> > I am trying to produce a summary statistics on a series of 
variables
> > using the command SUM inside a macro subroutine. Apparently, my
> > "try=off" program (see below) is not working because a syntax 
> error. I
> > cannot find the error. Would anybody be able to see it?
> >
> > Thanks!
> >
> <snip>
> > . local samp1 "if prown3==0"
> >
> > . foreach v of varlist `v1' {
> >  2. sum `v1' if `samp1' [aw=`v1']
> >  3. }
> > if not found
> > r(111);
> 
>
*
*   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