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]

Re: st: Making vce(robust) the default


From   Richard Williams <[email protected]>
To   [email protected]
Subject   Re: st: Making vce(robust) the default
Date   Fri, 05 Aug 2011 22:52:09 -0500

At 08:09 PM 8/5/2011, Stas Kolenikov wrote:
On Thu, Aug 4, 2011 at 2:20 PM, Richard Williams
<[email protected]> wrote:
> As for checking for the use of svy:, it can be done now in Stata 12. Suppose
> your program is called myprog.ado. Create another program called
> myprog_svy_check.ado. svy: will check to see if this program exists, and if
> it does it will execute it. For example,
>
> program myprog_svy_check
>         version 12
>         display "svy is being used"
> end
>
> Maybe I can have it set some global parameter so the program knows svy: is
> being used.

That's a freaking dirty programming trick... or undocumented (and
barely supported) implementation detail, depending on how you view
this. It may be usable at the moment, but it may die off with the next
release, or something. I mean, it's better than nothing, but you would
want to program it very defensively, just for the case that something
gets broken down: (1) your global is set by somebody else; (2) -svy-
decides to call another program; (3) some other unpredictable
circumstances that may cause wrong behavior of your program.

My approach is undocumented (in the manuals) but documented online. In Stata 12, type

help svy_parsing

For those not blessed with Stata 12 yet, part of the online help says

"Suppose that we developed an estimation command and added support for svy. Let's assume our command is called myest and that there is an option called lrstats that is not allowed with the svy prefix. When svy is used with myest, svy will look for a program named myest_svy_check. If myest_svy_check exists, svy will call it with the options specified in the call to myest, along with the vce() option containing the VCE method that will be used."

The code that makes this all possible occurs early in _svy_check_cmdopts.ado, which is called by svy.

You are right that there is some risk. -help undocumented- says

"An undocumented command is a command of very limited interest, usually interesting only to Stata programmers, and is used by StataCorp in developing Stata. Undocumented commands are documented online, but their documentation does not appear in the printed manuals. That undocumented commands are documented at all shows the "openness" of the Stata software. Undocumented commands may change their syntax or behavior in subsequent releases of Stata, though this is rare, so use them with caution."

I think this has the potential to be an extremely useful feature though, so I hope it sticks around for all eternity. ;-) My gologit2 program sometimes works correctly with svy:, and other times it does not. I can fix that now with a gologit2_svy_check program.

I do agree that global variables can be problematic. I'll probably use more bizarre names. In my code I made a point of dropping the global as soon as it was no longer needed so it would be unlikely to stick around and haunt me.

If I had to find another way to do it - svy: uses iweights when it calls a program. So, you could check to see if iweights were being used. That would mostly create problems if by some wild chance the user actually did want to use iweights, so the approach I outlined above seems more foolproof to me.




-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME:   (574)289-5227
EMAIL:  [email protected]
WWW:    http://www.nd.edu/~rwilliam

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