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

st: RE: [clustered] random draws

From   "Kieran McCaul" <>
To   <>
Subject   st: RE: [clustered] random draws
Date   Fri, 29 May 2009 07:26:18 +0800


How about something like this. It creates 10 clusters. I've left the
sd's set at 5, but you could change these to affect the degree of

set seed 1234

forvalues i = 1/10  {
local m1 = uniform()*100
local m2 = uniform()*100

matrix m = (`m1',`m2')
matrix sd = (5,5)
drawnorm x y, n(10) means(m) sds(sd)

tempfile ttt`i'
save ttt`i', replace


use ttt1, clear
forvalues i = 2/5  {
append using ttt`i'
drop if x<0 | x>100
drop if y<0 | y>100

scatter y x

Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2701
Fax: (08) 9224 8009
Man is a credulous animal, and must believe something; in the absence of
good grounds for belief, 
he will be satisfied with bad ones. Bertrand Russell 

-----Original Message-----
[] On Behalf Of Susan Olivia
Sent: Friday, 29 May 2009 6:17 AM
Subject: st: [clustered] random draws

Dear Stata lister,

I am generating x and y coordinates based on random draws
from a uniform distribution with a minimum value of 0 and
maximum value of 100 - which has the effect of randomly
locating the data in a 100 by 100 square. 

The question that I want to ask:  I would like generate
clustered pattern from the generated x and y coordinates
[say 10 observations that close to each other forming a
cluster]. Is this something possible that I can do in Stata?

Thanks in advance,


*   For searches and help try:

*   For searches and help try:

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