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

From |
"R.E. De Hoyos" <redeho@hotmail.com> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Identifying single psu within strata |

Date |
Fri, 29 Apr 2005 21:09:08 +0100 |

Many thanks to Nichols and Jeff.

I run the -singleton- code and it is working perfectly.

Best,

Rafa

----- Original Message ----- From: "Jeff Pitblado, StataCorp LP" <jpitblado@stata.com>

To: <statalist@hsphsun2.harvard.edu>

Sent: Friday, April 29, 2005 8:45 PM

Subject: Re: st: Identifying single psu within strata

R.E. De Hoyos <redeho@hotmail.com> asks about generating an indicator variable

that identifies strata with a single PSU:

I want to run wage regressions for several population groups. EstimationsThis feature was added to -svydes- in Stata 9. -svydes- now has a

have to take care of the survey design (svy). The problem is that for some

of the groups there are strata with a single psu (primary samplying unit).

Using -svydes- I can identify does strata, for example:

For wage equation: svyreg wage_1 varlist_1:

svydes wage_1 varlist_1

And Stata will highlight those strata with a single psu. How can I create a

dummy variable that indicates weather a strata has a single psu given the

variables that I want to use for the analysis?

In other words I want a dummy variable that takes the value of 1 if -svydes-

highlights a strata.

-generate()- option that generates this variable.

In Stata 8, there is no such option; however, the output of -svydes- should

identify the "singleton" strata using the values from the strata variable that

was -svyset-. You can use the output from -svydes- to generate a new

variable.

If you need to do this for a bunch of different groups, you will need to write

a program. You can start with the following:

***** BEGIN: singleton.ado

program singleton, sort

version 8

syntax [varlist(numeric default=none)] [if] [in], ///

STRata(varname) gen(name) [ PSU(varname) ]

confirm new var `gen'

marksample touse

if "`psu'" == "" {

tempvar psu

gen `psu' = _n

}

tempvar u

sort `touse' `strata' `psu'

quietly by `touse' `strata' `psu': gen `u' = _n == 1

quietly by `touse' `strata': replace `u' = sum(`u')

quietly by `touse' `strata': replace `u' = cond(`u'[_N] == 1, 1, 0)

quietly replace `u' = . if !`touse'

rename `u' `gen'

end

***** END: singleton.ado

Here is a log using the above -singleton- program with the auto data:

***** BEGIN:

. clear

. sysuse auto

(1978 Automobile Data)

. * Example with no singleton strata

. singleton, strata(rep) gen(jj)

. tab rep if jj

no observations

. * Example with 2 singleton strata

. singleton, strata(rep) psu(for) gen(kk)

. tab rep if kk

Repair |

Record 1978 | Freq. Percent Cum.

------------+-----------------------------------

1 | 2 20.00 20.00

2 | 8 80.00 100.00

------------+-----------------------------------

Total | 10 100.00

. * Proof that 2 categories of -rep78- have only "Domestic" cars

. tab rep for

Repair |

Record | Car type

1978 | Domestic Foreign | Total

-----------+----------------------+----------

1 | 2 0 | 2

2 | 8 0 | 8

3 | 27 3 | 30

4 | 9 9 | 18

5 | 2 9 | 11

-----------+----------------------+----------

Total | 48 21 | 69

***** END:

--Jeff

jpitblado@stata.com

*

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

**References**:**Re: st: Identifying single psu within strata***From:*jpitblado@stata.com (Jeff Pitblado, StataCorp LP)

- Prev by Date:
**Re: st: Identifying single psu within strata** - Next by Date:
**st: generate a positive-valued random variable** - Previous by thread:
**Re: st: Identifying single psu within strata** - Next by thread:
**st: generate a positive-valued random variable** - Index(es):

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