I want to perform 1,000 iterations, where each iteration generates 30 random coin flips, counts the heads, and stores the result in a single dataset with 1,000 rows (one for each iteration).
currently I have this code:
if you delete the line with set obs = `n' it works but only insofar as it will be able to close the loop. The number of "coin flips" for each sample will be equal to 'reps'.
the code within the loop,
works like a charm for one iteration. So how can I embed the latter into the former?
also this is my first post. please advise if I'm posting code incorrectly.
Thanks!
currently I have this code:
HTML Code:
clear all local n 30 local reps 1000 set obs `reps' gen headcount = . forvalues i =1/`reps' { set obs = `n' gen u = runiform(0,1) // random value between 0 and 1 gen heads = u > 0.5 // categorical data, 1 if heads, 0 if tails // count if heads==1 replace headcount = r(N) in `i' drop heads drop u }
the code within the loop,
Code:
set obs 30 // 30 coin flips // gen u = runiform(0,1) // random value between 0 and 1 gen heads = u > 0.5 // categorical data, 1 if heads, 0 if tails // summarize heads count if heads==1
also this is my first post. please advise if I'm posting code incorrectly.
Thanks!
Comment