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

st: Re: sampling question

From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: sampling question
Date   Wed, 10 Mar 2004 14:38:17 -0500

You will probably be best off using a loop and a postfile.  I've done this
kind of thing farily often, here's an ado that should work:

program define prob1
version 8.2
syntax using , saving(str) [reps(integer 100) samples(integer 30)
samplen(integer 100)]
tempname post
local tokeep=`samples'*`samplen'
postfile `post' b1 b2 using `saving'
set seed 1234567
forval rep=1(1)`reps' {
use `using', replace
gen rand=uniform()
sort rand
qui keep in 1/`tokeep'
gen int sample=int((_n-1)/`samplen')+1
collapse y x1 x2 , by(sample)
qui reg y x1 x2
local beta1=_b[x1]
local beta2=_b[x2]
post `post' (`beta1') (`beta2')
postclose `post'
use `saving', replace

This ado is hardcoded for y x1 and x2 as the variables, but allows you to
specify the number of overall replications, the subsample sizes and number
of subsamples for each run.  It also specifies a seed to provide
repeatability.  You could use it like this:

prob1 using mydata, saving(myresults)

Michael Blasnik
[email protected]

----- Original Message ----- 
From: "ACHINTYA RAY" <[email protected]>
To: <[email protected]>
Sent: Wednesday, March 10, 2004 1:58 PM
Subject: st: sampling question

> Sorry for posting a somewhat long query. I'll appreciate if you can help
> perform the following operation is Stata. Bootstrap commands in Stata
> me perform some of the things. Specifically, I am looking for a solution
> where (sort of) bootsrap is allowed within a bootstrap setup.
> Suppose I have a sample of 20,000. I have 3 variables: y, x1 and x2.
> Step 1: Draw 30 samples of size 100 each.
> Step 2: Calculate mu(y), mu(x1), mu(x2) for each of the subsamples.
> Step 3: Create a matrix of mu(y), mu(x1), mu(x2). Clearly, it will be a
> matrix of dimension 30x3. Let's call it [Y X1 X2]
> Step 4: Run the model Y=a + b1*X1 + b2*X2 + e
> Step 5: Create file to save estimated b1 and b2.
> Step 6: Repeat Steps 1 through 5 several times (100 times) to obtain a
> matrix of estimated b1 and b2s (100x2 in dimension).
> While I can create a grand file of all the means, I am having difficulty
> creating the subroutine described in Steps 1 through 5.
> Thanks
> Achintya Ray
> Senior Research Associate
> Department of Medicine
> Vanderbilt University
> [email protected]
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

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