Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: re: Sample with weights


From   Nick Winter <nw53@cornell.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: re: Sample with weights
Date   Mon, 03 Oct 2005 09:53:43 -0400

Doesn't work.

First, you need to sort the other direction.

But more seriously, this does not generate selection probabilities proportional to size. Consider this code, which creates fake data, then draws 500 samples of 200 using this methed. The graph at the end makes clear that the selection probabilities are not proportional to size:

clear
set obs 1000
gen firm = _n
set seed 12345678
gen size = int(uniform()*100) + 1
gen sampled = 0

forval i=1/500 {
gen ppsorder = uniform() * size
gsort -ppsorder
qui replace sampled = sampled+1 if _n <= 200
drop ppsorder
}

graph twoway scatter sampled size

--Nick WInter



At 11:04 AM 10/1/2005, you wrote:

This is simple, produces a sample of exactly the desired size,
and I believe fulfills the condition of the probability of selection
being proportional to size .
*Assume "Size" is the company size variable, and M is the desired sample size
gen ppsorder = uniform() * Size
sort ppsorder
keep if _n <= M
drop ppsorder

Yes, sorting the file is a bit clumsy, but this is presumably a one time thing,
not something appearing inside a loop.

Regards,


=-=-=-=-=-=-=-=-=-=-=-=-=
Mike Lacy
Fort Collins CO USA
(970) 491-6721 office
________________________________________________________
Nicholas J. G. Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government nw53@cornell.edu e
Cornell University falcon.arts.cornell.edu/nw53 w
308 White Hall
Ithaca, NY 14853-4601

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