+ Reply to Thread
Results 1 to 4 of 4

Aggregate by ID number and Counting

  1. #1
    Registered User
    Join Date
    03-15-2011
    Location
    Iowa City, IA
    MS-Off Ver
    Excel 2013
    Posts
    29

    Aggregate by ID number and Counting

    I have a file with Id numbers of clients. Each of these clients may have 0 to 28 criminal records. The offenses of these clients could have occurred before or after their treatment discharge date. My variables are:

    Id, name, discharge date, arrest date.

    What I want is to aggregate by ID number and create two new variables crmBefore and crmAfter that counts the number of crimes that occurred prior to the discharge date and after the discharge date. For example, this is what I have now:

    Id DisChrDat ArrDate
    1 1/1/2008 11/1/2009
    1 1/1/2008 5/1/2009
    1 1/1/2008 2/1/2007
    1 1/1/2008 3/1/2007
    2 3/1/2009 10/1/2008
    2 3/1/2009 4/6/2008
    2 3/1/2009 6/11/2008
    2 3/1/2009 5/21/2008
    2 3/1/2009 2/12/2010

    And this is what I want (the arrest date becomes irrelevant)

    Id DisChrDate ArrDate crmBefore CrmAfter
    1 1/1/2008 NA 2 2
    2 3/1/2009 NA 4 1

    I’m weak at VBA and I have been doing this manually which takes a long time. I hope someone can help me.

    Thanks

    Zeda
    Last edited by ZedaG; 04-26-2011 at 07:41 AM.

  2. #2
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Aggregate by ID number and Counting

    You seem to be assuming that the date of the crime is synonymous with the arrest date. That is frequently not the case. I suggest you change your headings to ArrestBefore and ArrestAfter OR a much better alternative would be to get the dates of the crimes.

    And VBA wouldn't be required for this.
    Last edited by Cutter; 04-25-2011 at 09:06 AM.

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Aggregate by ID number and Counting

    Does this help?
    In H2
    Please Login or Register  to view this content.
    In I2
    Please Login or Register  to view this content.
    Both are array formluae so confirm with Ctrl+Shift+Enter NOT just Enter
    Drag/Fill Down as required
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Registered User
    Join Date
    03-15-2011
    Location
    Iowa City, IA
    MS-Off Ver
    Excel 2013
    Posts
    29

    Re: Aggregate by ID number and Counting

    Thanks Marcol. yes this realy helps! I have spent so much time doing this by hand. i'm sorry if I posted in the wrong forum, but i do appreciate your time in helping me.

    Zeda!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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