Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Problem with stsplit and survey data that isn't


From   "Richard Atkins" <Richard.Atkins@lshtm.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Problem with stsplit and survey data that isn't
Date   Tue, 24 Oct 2006 14:54:01 +0100

Hi Nick,

Thanks for your detailed answer.  Despite writing ado files myself I
wasn't familiar with 'viewsource' and although it appeared that the
saved file was carrying svyset information I was actually a little
incredulous at this and expected to be told I had missed something else.
 In fact I can now see it's sensible that svyset information should
persist in the dta file (presumably attached to some variables) and have
found the comment in the help file to this effect. Unfortunately I've
never had cause to svyset data and just assumed svyset would work the
same way as stset i.e. no persistence across saves.

Thank you. I am both humbled and educated. ;-)

Richard A.


>>> "Nick Cox" <n.j.cox@durham.ac.uk> 24/10/2006 14:17 >>>
Stata itself can help answer questions like this. 
In this case, I have knowledge of -svy- of measure 
zero, but how did I try to find out something for you? 

A first principle is that most Stata commands 
are just more Stata, and as such often fairly
intelligible even if you are not a user-programmer. 
Thus command -foo- is usually defined by -foo.ado-. 

The second principle is that -viewsource- will
show you the code: 

In this case 

. viewsource stsplit.ado 

opens a window on the code, which starts like
this. (You don't need even to work out where it
is on your system, as -viewsource- gets that
job done first.) 

*! version 2.2.4  15sep2004
program define stsplit
        version 7, missing

        if _caller() < 6 {
                ztspli_5 `0'
                exit
        }
        st_is 2 full

        if `"`_dta[st_id]'"' == "" {
                di as err /*
                */ "stsplit requires that you have previously stset an
id() variable"
                exit 198
        }

        capture svyset
        if "`r(_svy)'" ~= "" {
                di as err "stsplit not allowed with survey data"
                exit 498
        }

Thus, as you surmise, -stsplit- looks for indications that
you, or whoever set up the data, have previously declared 
-svy- settings to Stata. In this case, the trail suggests 
a look at -help svyset-, which 
indicates a way to clear such settings, so the rather
drastic expedient you have outlined is not necessary at all. 

There is more on -viewsource- in a Stata Journal Tip, 

SJ-6-1  pr0022  . . . . . . . . . . . Stata tip 30: May the source be
with you
        Q1/06   SJ 6(1):149--150                                 (no
commands)
        tip for using viewsource to locate and view source
        code or text files

which is also reprinted in the collection of 33 Stata Tips 
available at modest price from StataCorp. 

Nick 
n.j.cox@durham.ac.uk 

Richard Atkins
 
> I've solved my problem but I don't know why and I'd like to
understand
> better.
> 
> I was trying to use the stsplit command on a set of data and 
> getting an
> error message "stsplit not allowed with survey data".  
> I checked and my do file did not contain any svy... commands. I also
> checked that my data had no underscore prefixed variables 
> from any prior
> svy commands that may have been used historically so I 
> couldn't see why
> stata thought this data had been identified as survey data.  Next
step
> was to save the dataset and then try again with a minimal 
> command set of
> clear, use, stset and then stsplit.  Still the same error.  Finally
I
> 'keep'ed just the four variables required for these commands 
> (ageentry,
> ageexit, dead, id) and tried again and it worked.
> 
> It appears that something stored in or attached to one of the
dropped
> variables identified this data as survey data. This particular
dataset
> contains about 400 variables so I am reluctant to use trial 
> and error to
> identify the culprit, so can anyone tell me what might cause this?

*
*   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/
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index