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]
Re: st: How to Randomly Assign 4 Integers to a Dataset?
From
"Dimitriy V. Masterov" <[email protected]>
To
[email protected]
Subject
Re: st: How to Randomly Assign 4 Integers to a Dataset?
Date
Thu, 11 Nov 2010 18:25:01 -0500
I think you may find the mod() function useful for this:
generate rannum = uniform()
sort rannum
gen x=.
replace x=1 if mod(_n,4)=0
replace x=5 if mod(_n,4)=1
replace x=15 if mod(_n,4)=2
replace x=20 if mod(_n,4)=3
On Thu, Nov 11, 2010 at 6:17 PM, Carly Petracco <[email protected]> wrote:
> I have 4 values that I want to randomly assign to the observations in
> my dataset.
> I do not want this to occur over a range (I know about runiform), all
> I have 4 integers (i.e. 1, 5, 15, 20) that I want to randomly assign
> to my observations, how do I do that?
> I have not been able to find a solution for this problem on the web
> or in previous questions, so any help would be greatly appreciates!
>
> Best,
> Charlie
> *
> * 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/