?
Solved

Random classification of records

Posted on 2014-04-07
8
Medium Priority
?
94 Views
Last Modified: 2014-04-09
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
0
Comment
Question by:dougf1r
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39984338
if you place the formula in a spare column and recalc the sheet, you should be close.
RANDBETWEEN( 1, 5 ),
you should then sum each assignment (1-5) to ensure you have a balanced distribution.
0
 
LVL 1

Author Comment

by:dougf1r
ID: 39984352
How can this be modified such that I have 4 equal-sized groups (n=40) and one group with n=41?
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39984362
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?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:dougf1r
ID: 39984393
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?
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39984467
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.RandBetween(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
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39984485
The above isn't correct - please wait for a better response - I have to go.
0
 
LVL 7

Accepted Solution

by:
COACHMAN99 earned 2000 total points
ID: 39984747
Here you go:
Sub PopVals()
Dim vval As Long
Dim counts(5) As Long
x = 1
Range("C1:C201") = ""
While x <= 201
  vval = WorksheetFunction.RandBetween(1, 5)
  Worksheets("Sheet2").Cells(x, 3) = vval
  vval = vval - 1
  If counts(vval) < 40 And vval < 4 Then
    counts(vval) = counts(vval) + 1
    x = x + 1
  End If
  If counts(vval) < 41 And vval = 4 Then
    counts(vval) = counts(vval) + 1
    x = x + 1
  End If
Wend

End Sub
0
 
LVL 1

Author Comment

by:dougf1r
ID: 39990166
Works perfectly. Many thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question