Reproducing Random Samples

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Reproducing Random Samples

Jignesh Sutar
I have created a macro which samples (with replacement) from a population
dataset and then calculates various summary statistics.
The current set up is that macro gets the the population file and then uses
"COMPUTE draw=uniform(1)" to draw a random sample,
calculate the relevant statistics and save them as single row in a new
dataset. The macro then repeats this, saving each iteration as a new row in
the final dataset.

There are certain samples which need further investigation so the question I
have is, how do I reproduce these samples?

Would setting the seed number to the iteration number be a solution?

Many thanks in advance.

Jigs

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Reproducing Random Samples

Albert-Jan Roskam
Hi,
Try something like:

set rng=mt mtindex= 20090120.
sample .10.

Cheers!!
Albert-Jan


----- Original Message ----
From: J Sutar <[hidden email]>
To: [hidden email]
Sent: Monday, January 19, 2009 5:02:02 PM
Subject: Reproducing Random Samples

I have created a macro which samples (with replacement) from a population
dataset and then calculates various summary statistics.
The current set up is that macro gets the the population file and then uses
"COMPUTE draw=uniform(1)" to draw a random sample,
calculate the relevant statistics and save them as single row in a new
dataset. The macro then repeats this, saving each iteration as a new row in
the final dataset.

There are certain samples which need further investigation so the question I
have is, how do I reproduce these samples?

Would setting the seed number to the iteration number be a solution?

Many thanks in advance.

Jigs

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Reproducing Random Samples

Jignesh Sutar
I don't think that would work as it would give me the same sample at each
loop/iteration (if I have understood correctly?)...?
I'll provide some more information/code...

The macro I have setup is adapted from a macro available on Ray Levesque
site (
http://www.spsstools.net/Syntax/Bootstrap/GetRandomSampleOfVariousSizeCalcStats.txt).<http://www.spsstools.net/Syntax/Bootstrap/GetRandomSampleOfVariousSizeCalcStats.txt>
I have added my own calculations into the body of the macro but the
setup/structure of the macro is identical to the code below.

* -------------------DEFINE MACRO
---------------------------------------------.
DEFINE !sample(myvar !TOKENS(1)
/nbsampl !TOKENS(1)
/size !CMDEND).
* myvar = the variable of interest (here we want the mean of salary)
* nbsampl = number of samples.
* size = the size of each samples.

!LET !first='1'
!DO !ss !IN (!size)
!DO !count = 1 !TO !nbsampl.

GET FILE='c:\Program Files\SPSS\employee data.sav'.

COMPUTE draw=uniform(1).
SORT CASES BY draw.
N OF CASES !ss.

COMPUTE samplenb=!count.
COMPUTE ss=!ss.

AGGREGATE
  /OUTFILE=*
  /BREAK=samplenb
  /!myvar = MEAN(!myvar) /ss=FIRST(ss).

!IF (!first !NE '1') !THEN
ADD FILES /FILE=*  /FILE='c:\temp\sample.sav'.
!IFEND
SAVE OUTFILE='c:\temp\sample.sav'.
!LET !first='0'

!DOEND.
!DOEND.

VARIABLE LABEL ss 'Sample size'.
EXAMINE
  VARIABLES=salary BY ss /PLOT=BOXPLOT/STATISTICS=NONE/NOTOTAL
  /MISSING=REPORT.

!ENDDEFINE.
* ----------------END OF MACRO
----------------------------------------------.
* Call macro (parameters are number of samples (here 20) and sizes of sample
(here 5, 10,15,30,50).
* Thus 20 samples of size 5.
* Thus 20 samples of size 10, etc.
set mprint on.
!sample myvar=salary nbsampl=5 size= 15 30.
set mprint off.




The code above creates 10 samples - 5 of size 15 and 5 of size 30. How do I
reproduce the datasets of any one of those 10 samples?

Cheers
Jigs

2009/1/20 Albert-jan Roskam <[hidden email]>

> Hi,
> Try something like:
>
> set rng=mt mtindex= 20090120.
> sample .10.
>
> Cheers!!
> Albert-Jan
>
>
> ----- Original Message ----
> From: J Sutar <[hidden email]>
> To: [hidden email]
> Sent: Monday, January 19, 2009 5:02:02 PM
> Subject: Reproducing Random Samples
>
> I have created a macro which samples (with replacement) from a population
> dataset and then calculates various summary statistics.
> The current set up is that macro gets the the population file and then uses
> "COMPUTE draw=uniform(1)" to draw a random sample,
> calculate the relevant statistics and save them as single row in a new
> dataset. The macro then repeats this, saving each iteration as a new row in
> the final dataset.
>
> There are certain samples which need further investigation so the question
> I
> have is, how do I reproduce these samples?
>
> Would setting the seed number to the iteration number be a solution?
>
> Many thanks in advance.
>
> Jigs
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>
>
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD