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]
Re: st: Syntax to specify clustering on a variable or turn off clustering
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Syntax to specify clustering on a variable or turn off clustering
Date
Wed, 27 Mar 2013 16:51:44 +0000
Have a look at
SJ-9-3 pr0048 . . . . . . . . . Stata tip 79: Optional arguments to options
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q3/09 SJ 9(3):504 (no commands)
tip showing programmers how to provide an option that
can be specified with or without arguments
http://www.stata-journal.com/sjpdf.html?articlenum=pr0048
Nick
On Wed, Mar 27, 2013 at 4:41 PM, Nicholas Potter
<[email protected]> wrote:
> I'm trying to write a program that will use clustering on a variable by
> default, but also give the user the option to turn it off or to cluster on
> a different variable. The problem is that including both "cluster(varname)"
> and "nocluster" in the syntax definition results in the cluster option not
> being stored.
>
> For example:
>
> program define regress2
>
> syntax varlist [if] [in] [aw fw iw/] [, cluster(passthru) nocluster ]
> ...
> if "`cluster'"=="nocluster" {
> reg yvar xvars
> }
> else if "`cluster'"=="" {
> reg yvar xvars, cluster(foriegn)
> }
> else {
> reg yvar xvars, `cluster'
> }
>
> end
>
> This will default to cluster(foreign) regardless of whether a
> cluster(varname) option is passed:
>
> webuse auto, clear
> regress2 price mpg rep78 --> program clusters on foreign
> regress2 price mpg rep78, cluster(make) --> program clusters on foreign
> regress2 price mpg rep78, nocluster --> no clustering is used
>
>
> the second command should cluster on make instead of on foreign.
>
> Any thoughts or recommendations? I could change nocluster to clusteroff or
> something, but that wouldn't be in keeping with stata syntax convention.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/