Statalist The Stata Listserver


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

st: identify strata with one distinct value of psu


From   "Austin Nichols" <[email protected]>
To   [email protected], "Brent Fulton" <[email protected]>
Subject   st: identify strata with one distinct value of psu
Date   Mon, 18 Dec 2006 14:13:01 -0500

Brent--

There are a number of points here, so I will respond in a public forum.
First, my code is wrong when it computes a count of nonmissing psu by
stratum (which does *not* identify strata with a single distinct value
for psu, so the answer to my question "does that work?" is a decided
No).  Second, it seems to me that the -generate- option of official
Stata -svydes- does not work as advertised in the help file--can
someone verify and comment?  Third, I don't think that restricting the
regression using the subpop option should eliminate the problem--I
think you have to collapse strata and make a new strata_id variable
and issue a -svyset- command to tell Stata what you've done.  Finally,
I don't see any problem with spaces or commas in the locals--perhaps
you can use display commands and verify that they are being defined
correctly?

Here are two ways of identifying strata with one distinct value of
psu, both of which are actually tested and seem to work:

webuse nhanes2, clear
replace sizp=. if psu==2 & str>10
svydes loglead sizp, gen(notok)
tab stra notok
egen not=max(notok), by(strat)
g ok=1-not
tab stra ok
qui reg $y $x if !mi(weight,psu,strata)
g new_psu=psu if e(sample)
egen sd_psu=sd(new_psu), by(strata)
qui levelsof strata if sd_psu>0, local(ok)
di "`ok'"
local oklist: subinstr loc ok " " ",", all
di "`oklist'"
g sok=inlist(strata,`oklist')
tab ok sok
svy, subpop(ok): reg $y $x


On 12/18/06, Brent Fulton <[email protected]> wrote:
Hi Austin,

Thank you for your help. I am having problems translating local(ok) so it
can be used in inlist. When I used your code below, all observations are
evaluated as true in the subpop command.

I see subinstr is supposed to replace spaces with commas, but it doesn't
seem to be doing that. I ran di `ok' and it produces a set of levels with no
spaces in between each level. When I run di `oklist', it produces a set of
levels separated by spaces (not commas).

I then tried:
levelsof strata if n_psu>1, local(ok) separate(,) /* which separates the
levels with commas */
And then tried using `ok' in inlist, but had the same problem as above.

Lastly, I tried using the function r(levels), which is outputted from
levelsof, but that also didn't work--same problem as above.

Any thoughts?

I think the general problem is that levelsof outputs the levels using one
type of syntax while the local macro stores it with a different syntax. This
has always been a frustration of mine using Stata--it's hard to figure out
the object that the information is stored in as well as the format of the
object. Any general advice would be appreciated.

Thanks,
Brent



-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Austin Nichols
Sent: Sunday, December 17, 2006 2:24 AM
To: [email protected]
Subject: Re: st: programming: automate identification of strata with one
psu


Brent--

Ignoring more "statistical" solutions such as multiple imputation or
estimating conservative SEs by ignoring strata, suppose you quietly
regress without -svy- then calculate n of PSUs per stratum if
e(sample) then issue a -levelsof- strata if the n exceeds 1, e.g.

qui reg y $x if !mi(weight,psu,strata)
g u_psu=1 if e(sample)
egen n_psu=count(u_psu), by(strata)
levelsof strata if n_psu>1, local(ok)
local oklist: subinstr loc ok " " ",", all
drop n_psu u_psu
svy, subpop(inlist(strata,`oklist')): reg y $x

Does that work?
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index