dougf1r
asked on
Random classification of records
Hello, I would like to randomly classify each of the attached 201 data records into one of 5 groups. Four of the groups will contain 40 records, and a fifth group will contain 41 records.
The group number (1-5) should be contained in column C.
Does anyone have a suggestion on how to randomly generate these five groups?
Many thanks in advance.
RandomClasses.xlsx
The group number (1-5) should be contained in column C.
Does anyone have a suggestion on how to randomly generate these five groups?
Many thanks in advance.
RandomClasses.xlsx
ASKER
How can this be modified such that I have 4 equal-sized groups (n=40) and one group with n=41?
Without running a small macro, populating each cell, and keeping a running total, I don't know. The above will be close.
Do you have to repeat this, or is it a once-off?
Do you have to repeat this, or is it a once-off?
ASKER
I will need to repeat this.
A small macro does seem that it would be most helpful. I am unsure of the proper code to carry this out.
Might someone be comfortable putting this code together?
A small macro does seem that it would be most helpful. I am unsure of the proper code to carry this out.
Might someone be comfortable putting this code together?
try this (you will need to add the vba-addin
In Excel, install the Analysis toolpack -VBA from Tools Addins.
Then in VBA, click Tools - References and put a checkmark on atpvbaen.xls
The problem with this is if you share your book, the other person must also have the analysis toolpack-vba addin installed.
Sub PopVals()
Dim vval As Long
Dim counts(5) As Long
x = 1
While x <= 201
vval = WorksheetFunction.RandBetw een(1, 5)
Worksheets("Sheet2").Cells (x, 3) = vval
vval = vval - 1
If counts(vval) < 51 And vval < 5 Then
counts(vval) = counts(vval + 1)
x = x + 1
End If
If counts(vval) < 52 And vval = 5 Then
counts(vval) = counts(vval + 1)
x = x + 1
End If
Wend
End Sub
In Excel, install the Analysis toolpack -VBA from Tools Addins.
Then in VBA, click Tools - References and put a checkmark on atpvbaen.xls
The problem with this is if you share your book, the other person must also have the analysis toolpack-vba addin installed.
Sub PopVals()
Dim vval As Long
Dim counts(5) As Long
x = 1
While x <= 201
vval = WorksheetFunction.RandBetw
Worksheets("Sheet2").Cells
vval = vval - 1
If counts(vval) < 51 And vval < 5 Then
counts(vval) = counts(vval + 1)
x = x + 1
End If
If counts(vval) < 52 And vval = 5 Then
counts(vval) = counts(vval + 1)
x = x + 1
End If
Wend
End Sub
The above isn't correct - please wait for a better response - I have to go.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works perfectly. Many thanks!
RANDBETWEEN( 1, 5 ),
you should then sum each assignment (1-5) to ensure you have a balanced distribution.