Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Kieran McCaul <kieran.mccaul@uwa.edu.au> |

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

Subject |
RE: st: RE: simulation: finding the winner, and generating unique values |

Date |
Tue, 28 May 2013 09:56:23 +0800 |

... I think you have the variables created in the wrong order; you need to create the volunteers and then assign the questions. The following creates 20 records, 4 per volunteer. Then it assigns the questions, 1 to 4, in random order to each volunteer. I don't see how this simulates anything however, because the answer - correct - is assigned independently, so there will be no association between the order of the questions and the correct answer. clear set seed 12358 set obs 20 gen volunteer = mod(_n,5) + 1 sort volunteer by volunteer: gen byte question = _n gen rnumb = uniform() sort volunteer rnumb gen byte correct = uniform()>=0.5 -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael McCulloch Sent: Saturday, 25 May 2013 11:10 PM To: statalist@hsphsun2.harvard.edu Subject: Re: st: RE: simulation: finding the winner, and generating unique values Thank you Kieran, What you suggest is exactly what I intended. This is a simulation based on an educational testing project, in which a sequence of questions (denoted by variable A), are posed to five volunteers (denoted by variable B) in sequence (hence needing 1-5 for each level of A). And, they will each get the question correct, or not (hence 0 or 1 for C). What you suggest is perfect! I have two other questions on which to ask your coding advice: 1. The sequence in which volunteers answer the question varies. Thus, I wish to randomly assign the sort order of 1-5, within each level of A. 2. Each volunteer will encounter many questions within a day's work, and I wish to test whether being the first to address a question has an effect on success. Thus, I wish to count, (and test if possible) the total number of correct answers each volunteer gets in a day's work, and whether who goes first (or second, and so on...) influences performance. Any further advice would be much appreciated, as I appreciate what you've already suggested. Best wishes, Michael McCulloch -- Pine Street Foundation, since 1989 124 Pine Street | San Anselmo | California | 94960-2674 P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org On May 24, 2013, at 8:40 PM, Kieran McCaul <kieran.mccaul@uwa.edu.au> wrote: > ... > > I'm not quite sure what the intent of the simulation is. > > 1. How can I simulate B so that only unique values of 1-5 are created? > > I don't understand what you mean here, particularly given that the code you use is under a comment "* simulate variable: B (values 1-5 sampled without replacement) ". > > There are 20 observations, 5 per level of "a". The only way that "b" can be assigned the values 1 to 5 without replacement is by assigning them within "a". > > I don't think this is what you are trying to do, but if it is, the following will do that: > > > clear > set seed 12358 > * simulate A > set obs 20 > > gen byte a = mod(_n,4) + 1 > > sort a > by a:gen byte b=_n > > gen byte c = uniform()>=0.5 > > > > > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael McCulloch > Sent: Saturday, 25 May 2013 3:31 AM > To: statalist@hsphsun2.harvard.edu > Subject: st: simulation: finding the winner, and generating unique values > > Greetings! > > * I have three questions related to the following data simulation. > * 1. How can I simulate B so that only unique values of 1-5 are created? > * 2. Is there a more elegant way to code simulation of variable B? > * 3. How can I identify which variable B had the highest total count of C, within levels of A? > > clear > set seed 12358 > * simulate A > set obs 20 //create 20 observations > gen a=1 in 1/5 > replace a=2 in 6/10 > replace a=3 in 11/15 > replace a=4 in 16/20 > > * simulate variable: B (values 1-5 sampled without replacement) gen b=. > replace b=(1 + int(5*runiform())) if a==1 > replace b=(1 + int(5*runiform())) if a==2 > replace b=(1 + int(5*runiform())) if a==3 > replace b=(1 + int(5*runiform())) if a==4 > > * simulate variable: C > gen c1=uniform() //Generate n (equal chance of 0-1) > gen c=. > replace c=0 if c1<0.5 > replace c=1 if c1>=0.5 > drop c1 > list, noobs > > > > Best wishes, > Michael McCulloch, LAc MPH PhD > > -- > Pine Street Foundation, since 1989 > 124 Pine Street | San Anselmo | California | 94960-2674 > P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org > > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: simulation: finding the winner, and generating unique values***From:*Michael McCulloch <mm@pinestreetfoundation.org>

**st: RE: simulation: finding the winner, and generating unique values***From:*Kieran McCaul <kieran.mccaul@uwa.edu.au>

**Re: st: RE: simulation: finding the winner, and generating unique values***From:*Michael McCulloch <mm@pinestreetfoundation.org>

- Prev by Date:
**Re: st: Need help with working with multiple files** - Next by Date:
**Re: st: Need help with working with multiple files** - Previous by thread:
**Re: st: RE: simulation: finding the winner, and generating unique values** - Next by thread:
**st: generating random numbers without replacement** - Index(es):