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" <>
To   <>
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" <> 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'
        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
        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. 


Richard Atkins
> I've solved my problem but I don't know why and I'd like to
> 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
> 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
> '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
> variables identified this data as survey data. This particular
> 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:
*   For searches and help try:

© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index