+ Reply to Thread
Results 1 to 9 of 9

Help for classifying categorical variables to groups

  1. #1
    Registered User
    Join Date
    07-20-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    8

    Help for classifying categorical variables to groups

    Hi all,

    I need to classify categorical variables to groups and then calculate the sizes of the groups (frequency or percentage of the variables in the groups).

    I need help for the classification especially. I have a column of about 100 variables consisting of letters and numbers. The goal is to classify them by the first two letters. For example, if the cell value begins with ”AA” then it belongs to Group 1 and so on. I would like to create a column where each group is once and the amount of variables in that group is next to it in another column.

    Is this even possible? Any help for classifying categorical variables is much appreciated.

  2. #2
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Help for classifying categorical variables to groups

    Can you upload a sample workbook with how you hope to have the results look?
    Spread the love, add to the Rep

    "None of us are as smart as all of us."

  3. #3
    Registered User
    Join Date
    07-20-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    8

    Re: Help for classifying categorical variables to groups

    Here is a sample. So the data is on the column A and I want it to look like columns D and E in the sample. I would like to identify the groups from the first two letters of the code. All the codes beginning with HR belong to group Human Resources and FI to Finance and so on. The number in the column E indicates, for example, how many HR**** codes exist in the data.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Help for classifying categorical variables to groups

    The formula below should do the trick. For each group you will need to adjust the Group Code to return the correct frequency:

    Please Login or Register  to view this content.
    This obviously applies for Finance, but you will need to change the FI to BD, HR, KM, AC, etc. If the list for these groups is much larger, a hard-coded array or lookup table can be used to speed up the process.

  5. #5
    Registered User
    Join Date
    07-20-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    8

    Re: Help for classifying categorical variables to groups

    Thank you very much for this!
    One more question. Is there a formula that would give the group name as an outcome? Some way to identify the first two letters and transform them to text? FI to finance and so on by using a lookup table perhaps. My data is so damn huge...

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Help for classifying categorical variables to groups

    Quote Originally Posted by mcmahobt View Post
    E2: =SUMPRODUCT(--(LEFT($A$2:$A$11,2)="FI"))
    More efficient:

    =COUNTIF($A$2:$A$11,"FI*")

    Or, using a cell to hold FI:

    C2 = FI

    =COUNTIF($A$2:$A$11,C2&"*")
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Help for classifying categorical variables to groups

    If your group name is written out in column D, this will work:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-20-2016
    Location
    Denmark
    MS-Off Ver
    2016
    Posts
    8

    Re: Help for classifying categorical variables to groups

    Thank you so much both of you! Problem solved

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Help for classifying categorical variables to groups

    You're welcome. Thanks for the feedback!

+ 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. Replies: 1
    Last Post: 04-06-2016, 03:52 PM
  2. Categorical variables with data validation List
    By Arsenal1986 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-10-2015, 04:11 PM
  3. Removing Groups of data based on Single Variables
    By Hockey5djh in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-11-2014, 12:58 PM
  4. Replies: 1
    Last Post: 07-16-2013, 01:54 AM
  5. A Formula for classifying groups of numbers into a letter.
    By surfer1 in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 07-05-2013, 09:48 AM
  6. Separate variables into different groups
    By narayanyr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-08-2009, 08:44 AM
  7. charting categorical variables
    By tim4072 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-18-2007, 08:08 AM

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