| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Re: new sampling problem
Michael that is indeed the problem newvar1 is a variable (it comes from the
svmat) and it does only give the first value to the local macro and so that
is why the foreach command only works once.
I used the mkmat and the svmat to get round the preserve and restore
commands.
Cheers,
John
From: "Michael Blasnik" <[email protected]>
Reply-To: [email protected]
To: <[email protected]>
Subject: Re: st: Re: new sampling problem
Date: Tue, 19 Jun 2007 12:38:17 -0400
...
I don't really understand what you are doing here, but the most obvious
error is -local news=newvar1-. Where is newvar1 defined? If newvar1 is a
variable, then the local macro will only contain the first observation of
that variable because you can't assign a variable to a macro like that.
Your code is too convoluted for me to figure out how to fix it. I'm also
fairly certain that you don't want to use mkmat, restore, svmat in
sequence.
Michael Blasnik
----- Original Message ----- From: "John allfish" <[email protected]>
To: <[email protected]>
Sent: Tuesday, June 19, 2007 12:28 PM
Subject: Re: st: Re: new sampling problem
Thanks for this, and for the setting the seed advice.
I have tried to sort this out with this very crude program but it only
seems to do the sampling for one value of newvar1, can anyone help me with
this? the first part of the do file defines the data. The last part does
the sampling I am interested in. It is very, very crude - and it may seem
a little odd, although I know what I want to do.
clear
range y 1 10 10
sum y
gen income=.
replace income=1 in 1/4
replace income=2 in 5/8
replace income=3 in 9/10
gen sex1=.
replace sex1=2 in 1/5
replace sex1=1 in 6/10
gen sex2=.
replace sex2=1 in 1/3
replace sex2=2 in 4/5
replace sex2=3 in 6/10
tab income
tab sex1
tab sex2
preserve
sort sex2
contract sex2
tempvar newvar
samplepps newvar, size(_freq) withrepl ncases(100)
mkmat newvar
restore
svmat newvar
gen const=1
local news=newvar1
foreach val of local news{
samplepps sample`val', ncases(`val') withrepl size(const)
}
<snip>
*
* 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/
_________________________________________________________________
Win tickets to the sold out Live Earth concert! http://liveearth.uk.msn.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/