Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: Syntax to specify clustering on a variable or turn off clustering


From   Nicholas Potter <potter.nicholas@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Syntax to specify clustering on a variable or turn off clustering
Date   Wed, 27 Mar 2013 09:41:17 -0700

Hello -

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.

Thanks,
Nick

~nap
*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index