[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: generating random numbers from a specified list

From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: generating random numbers from a specified list
Date   Fri, 15 Aug 2008 17:38:24 +0200

The problem is not entirely clear to me, but sounds like a case for nested
-cond- statements as in

set obs 10000
g x=cond(runiform()<0.3, 10000, cond(runiform()<0.6, 10010,
cond(runiform()<0.9,10020, 10030)))

where x is drawn from (10000,10010,10020,10030) and you can specify the
probabilities for the runiform() function as you please...


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jochen Sp�th
Sent: Friday, August 15, 2008 5:21 PM
To: [email protected]
Subject: st: generating random numbers from a specified list

Dear statalisters,

trying to build up a new dataset which is (almost) entirely random I'm
confronted with the following problem: How can I tell Stata to generate a
variable by randomly picking  numbers from a (previously) specified list?
Here's a minimal example of what I want to do:

Data right looks like follows:

firm	year  az_ges  az_ges_vz
1000129	1975	15	11
1000129	1976	14	11
1000129	1977	8	6
1000129	1978	26	20

1000530	1993	12	9
1000530	1994	29	22
1000530	1995	26	20
1000530	1996	14	11
1000530	1997	18	14

and so on, where firm is the cross section identifier and year the time
variable. Note that data ist organised in long format.
Now, I'd like to add a variable which contains for each firm a number picked
at random from a specified list, f.i. list=(10000,10005,10010, and so on).
This "random" number should be the same for firms across years. The list
exists already, albeit in a separate data file that can't be merged with the
data set at hand because it lacks the identifiers betnr and year.

Any suggestions?




Jochen Sp�th
Institut f�r Angewandte Wirtschaftsforschung (IAW) T�bingen
Ob dem Himmelreich 1
72074 T�bingen
Tel.: +49-(0)7071-9896-14
Fax: +49-(0)7071-9896-99
EMail: [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