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: Syntax to specify clustering on a variable or turn off clustering


From   Nicholas Potter <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index