+ Reply to Thread
Results 1 to 7 of 7

Choose Option Based on Percentage

  1. #1
    Registered User
    Join Date
    07-31-2017
    Location
    New Mexico
    MS-Off Ver
    2013
    Posts
    3

    Choose Option Based on Percentage

    Hello,

    I am trying to use excel to probabilistically choose 1 option from a set based on a percent or distribution. Is this possible?

    For example:

    If I wanted to assign a characteristic such as race and had the following categories: Caucasian, Hispanic, Asian, African American and Other. Then I had a % of the population that each of these categories was comprised of such as 35%, 20%, 15%, 20%, and 10% respectively. Then I wanted to basically ask a cell or list of cells to randomly choose one of the values based on the percentages. So that if I populated 100 cells the percentage in which I encountered each category would be approximately equal to the given percents but all assigned randomly. The end result is to help me randomly populate a list containing a bunch of characteristics to get the characteristics for a random person for some healthcare research. For instance, I might have race, income level, education level, age, ect, and each category would randomly be assigned to a given person based on the overall population data so that all of the random assignments depict a single person.

    If this doesn't quite make sense, please let me know. Any help is greatly appreciated!

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Choose Option Based on Percentage

    Please upload a workbook as it is a little confusing.

    Go Advanced>Manage Attachments. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    Let's say you have the percentages in F1:F5 (35%, 20%, 15%, 20%, and 10% ) and the corresponding race in G1:G5. Replace the percentages with the Running Totals.(0%,36%,56%,71%,91%). You can use this formula to randomly (within given percentiles) select race.

    =VLOOKUP(RANDBETWEEN(1,100), $F$1:$G$5,2)
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    07-31-2017
    Location
    New Mexico
    MS-Off Ver
    2013
    Posts
    3

    Re: Choose Option Based on Percentage

    I have added a workbook to try and illustrate what I am trying to do. I have to randomly fill in population data for people listed as subjects. In this example, I used race. The Race % is the breakdown of the approximate distribution of race in the population. I need to be able to automatically have the computer assign a race to each person randomly such that in a larger population, the percentage of randomly assigned races is close to the race % as it was originally given. Hope this makes more sense?
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Choose Option Based on Percentage

    Okay, I placed the formula that I mentioned in post 2 into your worksheet. Also in Columns E:G, I put the actual percentages based on picking 10 subjects, 30 subjects and 100 subjects (randomly). Theoretically, the more subjects you have, the closer the result will be to the entire population. Hitting F9 (shortcut for "recalculate") will change your results if you are looking to get values close to whole population with only 10 subjects.

    Questions?
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-31-2017
    Location
    New Mexico
    MS-Off Ver
    2013
    Posts
    3

    Re: Choose Option Based on Percentage

    Could you explain the concept behind the formula? For instance what it is actually doing in order? I still find myself a bit confused on what it is actually doing behind the scenes.

    Also, is there a way to stop it from recalculating when I change something else in the workbook? And at what population would you say that it would come close to the theoretical population %s? I tried it out at 1000, but some of the %s were still pretty far away, so is it based on a distribution around a %?

    And I'm uncertain where the running totals came from.
    Last edited by hzlanep; 07-31-2017 at 06:49 PM. Reason: added question

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Choose Option Based on Percentage

    Okay, starting with
    =VLOOKUP(RANDBETWEEN(1,100), $A$2:$B$6,2)
    RANDBETWEEN(1,100) is randomly choosing a number from 1 to 100. Every number has an equal chance of being chosen.

    Then it looks up this number in the table A2:B6 returning a value from the second column. The VLOOKUP looks down column A until it finds a value larger than the number (or comes to the end). Then looks across to pull the value from Col B.
    So there are 15 numbers between 86 and 100 or a 15% chance that the value will correlate to "Other". Between 1 and 30 there's a 30% chance of the number correlating to "White" and so forth.

    I would expect at 1000, the percentages would be pretty close to reality. Are you sure you modified your COUNTIF formulas properly?

    If you want everything to exactly fall into each bucket percentage wise then you're no longer truly random. It is easy to do that in Excel though

    To stop the Random values from recalculating each time you change something, set Calculations to Manual (Calculation Options on the Formulas Tab of the ribbon).

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Choose Option Based on Percentage

    I set up a sheet that will automatically match the number of subjects exactly to the demographics. Fractions of people will be placed in "Other"

    1 In G1, I entered the # of people in the study (20)
    2 In G2:G5, =INT($G$1*F2/100)
    3 In G6 (Other) = G1-SUM(G2:G5)

    4 Enter the Subject numbers into C2 down
    5 Enter the formula =RAND() into A2:A21

    6 In B2 copied down is this formula
    =INDEX($E$2:$E$6, MATCH(ROW()-1, $H$2:$H$6))
    which enters the appropriate number of each race.

    7 Next Copy Columns A and B and Paste Special Values (in place) to remove the formulas.
    8 Select data in Column A and B and Sort by A (Do not Extend selection if prompted)

    Sheet2 shows sheet before step 7 (formulas intact)
    Sheet 3 shows sheet after step 8.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Help - Choose a option in listbox then uptades another form
    By rssmith93 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-11-2016, 12:51 PM
  2. Choose item from a table based on percentage
    By metal.stuff in forum Excel General
    Replies: 8
    Last Post: 06-15-2016, 09:46 AM
  3. Two validations: first choose the sheet (1-5), then choose the option
    By bee88 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-17-2014, 08:12 AM
  4. [SOLVED] Choose the same option for all lists with a button
    By HugoRibeiro in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2013, 11:31 AM
  5. The option to choose data in Excel?
    By danakajoel in forum Excel General
    Replies: 4
    Last Post: 05-06-2010, 06:00 AM
  6. Choose and option and information pulls up
    By FPCMarietta in forum Excel General
    Replies: 9
    Last Post: 03-28-2007, 01:37 PM
  7. specify option to choose on alert msg?
    By ricksimm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1