+ Reply to Thread
Results 1 to 10 of 10

Formula to run random draw of specific number, then sum one variable and average another??

  1. #1
    Registered User
    Join Date
    04-08-2012
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    18

    Formula to run random draw of specific number, then sum one variable and average another??

    I am completely stumped on how to solve my problem. Hopefully someone here will know just the trick :-)

    I have data for groups of different sizes and I need to re-create these group characteristics using aggregate data from individuals.

    Specifically, I need to randomly select different numbers of individual level "Person IDs" (based on the group size) and then sum the values of variable X across those randomly selected people. Also, I need to average the values of variable Y across those randomly selected people.

    This sounds a bit confusing so I have attached a sample spreadsheet that clearly outlines my problem.

    I need to do this procedure for thousands of rows of data and would love to be able to automate it.

    Thanks so much in advance for your help!!! I really appreciate it!!

    Also crossposted here:

    http://www.mrexcel.com/forum/excel-q...n-random-draw-
    specific-number-changes-then-sum-one-variable-average-another-across-randoml
    y-selected-values.html#post3850066


    http://www.ozgrid.com/forum/showthre...493#post717493

    http://www.excelguru.ca/forums/showt...draw-of-specif
    ic-number-from-list-sum-one-variable-and-average-another&p=13545#post13545


    Attachment 327596Excel example2.xlsx
    Last edited by ea2146; 06-24-2014 at 03:27 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Formula to run random draw of specific number, then sum one variable and average anoth

    Hi,

    It's still confusing, at least to me. You have an output sheet with no values.

    In addition you mention that you need to select a maximum of 20 IDs yet I only see 5 IDs. As a minimum we'd like to see a list of say 100 IDs and an output sheet which clearly shows what results you expect along with notes that explain how you arrived at the results.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,373

    Re: Formula to run random draw of specific number, then sum one variable and average anoth

    Well, you don't give a very large table, but your table should be on a separate sheet. You need a column of random numbers: to not always select the same people, a macro re-calcs and pastes values next to the formula, one time for each row.

    Excel example2.xlsm
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Registered User
    Join Date
    04-08-2012
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Formula to run random draw of specific number, then sum one variable and average anoth

    Thanks so much for your comment. I apologize for the confusion. I have attached an updated spreadsheet with the structure of the output I would like.

    As to your question about drawing a maximum of 20 from a sample of 5, yes it seems counterintuitive, but that is exactly what I need. This means that there is a high probability that some of the 5 individual level values will be drawn more than once. This is ok for my purposes. For the first group, for example, I just need 20 draws (with replacement) to be made on the 5 individuals level values. Does this make more sense?

    Thanks again!!

    Excel example2_UPDATED.xlsx

  5. #5
    Registered User
    Join Date
    04-08-2012
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Formula to run random draw of specific number, then sum one variable and average anoth

    Thanks, Bernie!!

    This is very close to being perfect for my purposes. However, I must draw from a fixed number of individual level values. In the example I provided, there are only 5 individual level values. It's tricky because the first group size is 20 meaning that some of the individual level values will be drawn more than once in all likelihood. Is there any way to create a very similar macro to the one you created, but only use the 5 individual level values?

    Thanks so much! I have attached your solution with my proposed modifications, but now the macro does not work for groups with more than 5 people.

    example REVISED.xlsm

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,373

    Re: Formula to run random draw of specific number, then sum one variable and average anoth

    All macro, no formula...

    example REVISED.xlsm

  7. #7
    Registered User
    Join Date
    04-08-2012
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Formula to run random draw of specific number, then sum one variable and average anoth

    Wow, this is wonderful!! I can't thank you enough for taking the time to help!

    One final question - The example I provided was for simplicity, but in reality I need to scale this macro up to accommodate more than one sum and average variable. I have modified your spreadsheet to accommodate two "sum" variable and two "average" variables. However, it was not clear to me how to edit the macro syntax to do the same thing for additional variables.

    Could you add new syntax that will run the procedure on the two new variables I included? Thanks again, you have no idea how much this helps me!

    data_add_variables.xlsm

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,373

    Re: Formula to run random draw of specific number, then sum one variable and average anoth

    I have added comments, and the extra four lines required for the extra two columns.... I think you can figure out the pattern in the code.

    data_add_variables.xlsm

  9. #9
    Registered User
    Join Date
    04-08-2012
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Formula to run random draw of specific number, then sum one variable and average anoth

    This looks great. Thanks!!!

  10. #10
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,654

    Re: Formula to run random draw of specific number, then sum one variable and average anoth

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    http://www.excelguru.ca/forums/showt...erage-another&

+ 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] Macro to generate a random number between 2 specific values into specific cells.
    By Nerfmagnet in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-10-2013, 11:45 AM
  2. Random Number Generation with an Average
    By EJP520 in forum Excel General
    Replies: 9
    Last Post: 08-24-2011, 10:40 AM
  3. Is there a Formula for Random Draw
    By RodeoBrat in forum Excel General
    Replies: 2
    Last Post: 08-02-2011, 07:58 AM
  4. Replies: 2
    Last Post: 10-09-2009, 07:17 AM
  5. Random Winner Draw Formula Help
    By koba in forum Excel General
    Replies: 1
    Last Post: 09-18-2006, 11:50 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