Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Re: Invalid syntax in a program


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: Invalid syntax in a program
Date   Mon, 12 Jul 2010 22:56:31 +0200

<>

***********
su varname, mean
forv i=1/`r(max)'{
...
}
***********

See NJC`s http://www.stata-journal.com/article.html?article=st0135



HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Dani Tilley
Sent: Montag, 12. Juli 2010 22:08
To: stata
Subject: st: Re: Invalid syntax in a program

Hi guys,

Thanks for taking the time. It turns out that the problem was that the
program 
could not access local macros declared elsewhere in the program. So a -forv 
t=1/`max'- where max was a local declared outside the program would trigger
the 
invalid syntax error. I also noticed that this gave me an error:
program command, rclass
...
egen int max=max(varname) in 1

forv t=1/max[1] {
<code>
}
...
end

I did the following to fix it, but it feels clumsy:

egen int max=max(varname) in 1
local max=max[1]
drop max

forv t=1/`max' {
<code>
}


Any suggestions for a more elegant solution?

Thanks so much.

DF Tilley

----- Original Message ----

<>

Works for me too.   Try turning on your trace to see where it stops  (-set
trace 
on-)

~ Eric

<>


Does work for me:

***********
capture program drop command
program command, rclass
version  10.0
syntax varlist(min=1 max=10)
foreach v of local varlist {
       di in r "`v'"
}
end

drop _all

gen var1=.
gen var2=.
command var1 var2
***********


HTH
Martin


From: Dani Tilley <[email protected]>
To: stata <[email protected]>
Sent: Mon, July 12, 2010 3:19:08 PM
Subject: Invalid syntax in a program

Hi,

I'm trying to write a program that will do some fairly  involved
manipulations 
on variables. I'll spare you the code, but  I've tried it several times and
it 
works just fine. When I try to write a command that will do those operations
for 

me, I get invalid syntax.

capture program drop command
program command, rclass
version  10.0
syntax varlist(min=1 max=10)
foreach v of local varlist {
<working  code goes here>
}
end

command var1 var2
invalid  syntax r(198);

I also tried the following manually (not in a  program):

local b var1 var2
foreach v of local b{
<working  code>
} 

and everything went smoothly. So I'm completely  baffled as to why this
wouldn't 



work in a program with -foreach v of  local varlist-.

Any help is appreciated.

Thanks,
DF  Tilley


      
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index