Statalist


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

Re: st: AW: RE: generating random numbers from a specified list


From   "Sergiy Radyakin" <[email protected]>
To   [email protected]
Subject   Re: st: AW: RE: generating random numbers from a specified list
Date   Fri, 15 Aug 2008 12:17:14 -0400

May be this one will be easier?

generate Kreis=int(uniform()*439+1)
recode Kreis (1=10000 2=10010 3=10020 ....)

Not sure if all Kreise are equal in population though (this is what
uniform implies). You might want to weight the things somehow or
consider other distributions.

Regards,
   Sergiy Radyakin



On 8/15/08, Jochen Sp�th <[email protected]> wrote:
> Hello Martin,
>
> thanks a lot. Your suggestion is more or less what I need. The problem is only that my list contains 439 numbers of the German Kreise, so following your suggestion I would have to divide the 0-1 interval which is used by the -runiform- command into 439 equal parts and tell Stata manually to assign those 439 numbers. But for the first trials this will do.
>
> Thanks,
> Jochen
>
> -------------------------------------------------------------------------------------------
>
> Jochen Sp�th
>
> Dipl.-Volkswirt
>
> 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]
>
> IAW-Homepage: www.iaw.edu
>
> -------------------------------------------------------------------------------------------
>
>
>
>
> -----Urspr�ngliche Nachricht-----
> Von: [email protected] im Auftrag von Martin Weiss
> Gesendet: Fr 15.08.2008 17:38
> An: [email protected]
> Betreff: st: RE: generating random numbers from a specified list
>
> The problem is not entirely clear to me, but sounds like a case for nested
> -cond- statements as in
>
> ********
> clear*
> 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...
>
> HTH
> Martin
>
> -----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?
>
> Thanks,
>
> Jochen
>
> ----------------------------------------------------------------------------
> ---------------
>
> Jochen Sp�th
> Dipl.-Volkswirt
> 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]
> IAW-Homepage: www.iaw.edu
>
> ----------------------------------------------------------------------------
> ---------------
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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