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

RE: st: weight option after syntax


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   RE: st: weight option after syntax
Date   Sun, 25 Sep 2005 19:41:58 -0500

I suspect the problem is that "namelist" requires that the names listed use
the standard naming convention and names cannot begin with "["  If you use
the "if" option then parser knows that what follows cannot be part of
"namelist"


One alternative is to use "anylist"

program mycmd, rclass byable(recall)
version 9.1
syntax anything  [if] [in] [pweight]
	gettoken subcmd anything: anything
	gettoken lhs anything: anything
 	loc rhs `anything'
	di in r "`subcmd'"
	di in r "`lhs'"
	di in r "`rhs'"
	di in r "`weight'"
	di in r "`exp'"
end

Which now works:


. mycmd fubar price mpg  weight [anyhoo = (American) anyhow]  [pw = fore]
fubar
price
mpg  weight [anyhoo = (American) anyhow]
pweight
= fore

Hope this helps,
Scott

  

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Jun Xu
> Sent: Sunday, September 25, 2005 5:24 PM
> To: [email protected]
> Subject: RE: st: weight option after syntax
> 
> Sorry that I forgot to mention that I am using Stata 9.1.
> 
> 
> 
> Jun Xu
> Ph.D. Candidate
> Department of Sociology
> Indiana University at Bloomington
> 
> 
> 
> 
> 
> >From: "Jun Xu" <[email protected]>
> >Reply-To: [email protected]
> >To: [email protected]
> >Subject: st: weight option after syntax
> >Date: Sun, 25 Sep 2005 17:14:19 -0500
> >
> >I think I must miss something important here. I am trying to write a
> >command that simply invokes a stata command repeatedly and collect some
> >eret information. The following is the very beginning part of it (also
> >where the problem lies), and I am having problems with the [pw] option. I
> >inserted display commands to check if I am getting macro's that I want.
> Any
> >thoughts? Thanks a lot!
> >
> >==========================
> >  cap program drop mycmd
> >   program mycmd, rclass byable(recall)
> >    version 8.0
> >    syntax namelist [if] [in] [pw]
> >    gettoken subcmd namelist: namelist
> >    gettoken lhs namelist: namelist
> >    loc rhs "`namelist'"
> >
> >    di in r "`subcmd'"
> >    di in r "`lhs'"
> >    di in r "`rhs'"
> >    di in r "`weight'"
> >    di in r "`exp'"
> >
> >  end
> >
> >============================
> >
> >Everytime I launch the command by specifying weight option alone, I
> always
> >get an error message. Note that lwg is a real variable name and I have a
> >working data set in memory.
> >
> >******
> >. mycmd this is another issue [pw=lwg]
> >[ invalid name
> >r(198);
> >
> >end of do-file
> >r(198);
> >******
> >
> >However, if I work off a real data set and specify if condition before
> >[pw=lwg], everything works fine. Note here k5 is a real variable.
> >
> >******
> >. mycmd this is another issue if k5==3 [pw=lwg]
> >this
> >is
> >another issue
> >pweight
> >= lwg
> >******


*
*   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