+ Reply to Thread
Results 1 to 14 of 14

How to create municipality dummy variables in Excel

  1. #1
    Registered User
    Join Date
    07-13-2019
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel Office 2019
    Posts
    10

    Question How to create municipality dummy variables in Excel

    Hé there,

    I have the following problem: I have a dataset with corporations (codes) and (Dutch) municipalities (names) in which they have real estate development projects. Every row is a development project, so there are often multiple rows for each corporation code. What I now wish to do is make a new sheet in which each corporation code has only one row, each column is the name of a municipality (395 columns), and where they match there is a 1 if the corporation is active in that municipality and a 0 if it isn't.

    With what code could this be accomplished?

    I have included pictures of the datasets I speak of. The first shows the corporation codes (=Instellingsnummer) and active municipality (=Gemeentenaam). The second shows the format I want it in with again corporation codes under "Instellingsnummer" and the municipality names in the columns starting at Aa ten Hunze, Aalsmeer, Aalten etc.

    I really hope someone can help me with this! Huge amounts of thanks in advance!!
    Attached Images Attached Images
    Last edited by Jan Paul; 07-20-2019 at 09:50 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,396

    Re: How to create municipality dummy variables in Excel

    You can do this with PowerQuery in Excel 2019.

    Will you please attach a small sample Excel workbook? We are not able to work with or manipulate a picture of one and nobody wants to have to recreate your data from scratch.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    07-13-2019
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel Office 2019
    Posts
    10

    Re: How to create municipality dummy variables in Excel

    Yes very well.

    Here is a small sample of only 10 out of the 325 corporation codes in which sheet 1 represents the first picture in my original post and sheet 2 the second.
    Attached Files Attached Files

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to create municipality dummy variables in Excel

    Jan

    In Sheet2 of your sample you haven't seem to have added any 0/1s to indicate the active municipalities for the corporations in column B.

    For example, should there be a 1 in FO2 to indicate that the corporation Stichting Wonen Noordwest Friesland is active in the Leeuwarden municipality?
    If posting code please use code tags, see here.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: How to create municipality dummy variables in Excel

    Attached is a file showing a pivot table. Advise if this is something you can work with.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,396

    Re: How to create municipality dummy variables in Excel

    Here's a PowerQuery solution:

    M Code (column list - connection only):

    Please Login or Register  to view this content.
    M Code (matrix):

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-13-2019
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel Office 2019
    Posts
    10

    Re: How to create municipality dummy variables in Excel

    alansidman

    Thank you. What is the code you used to make this? If I could do this for every corporation I could replace all nonzero numbers with 1's to make the dummy variables.
    Last edited by Jan Paul; 07-20-2019 at 11:00 AM. Reason: Apparantly posting a quick reply does not include the name of the person you reply to, so I added that manually

  8. #8
    Registered User
    Join Date
    07-13-2019
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel Office 2019
    Posts
    10

    Re: How to create municipality dummy variables in Excel

    Norie

    Indeed, you are right on the money. 1's where that row's corporation has any activites, 0 of they do not.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: How to create municipality dummy variables in Excel

    No code required. Just inserted a Pivot Table. If you are unsure how to create PTs then look at this link

    https://www.contextures.com/CreatePivotTable.html

  10. #10
    Registered User
    Join Date
    07-13-2019
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel Office 2019
    Posts
    10

    Re: How to create municipality dummy variables in Excel

    AliGW

    I don't understand Power Query yet but I'll figure out how it works!
    Thank you!

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,396

    Re: How to create municipality dummy variables in Excel

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  12. #12
    Registered User
    Join Date
    07-13-2019
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel Office 2019
    Posts
    10

    Re: How to create municipality dummy variables in Excel

    It worked! Thank you all very much for your help. You are a bunch of legends whose reputations, I understand, are beyond repute.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,396

    Re: How to create municipality dummy variables in Excel

    What worked? Which did you go for, out of interest?

  14. #14
    Registered User
    Join Date
    07-13-2019
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel Office 2019
    Posts
    10

    Re: How to create municipality dummy variables in Excel

    I used the pivot table and put the corporation codes as rows, then the municipality names in the columns and had the values take the form as the number of times that municipality existed for that row / corporation. Then I copied the table, pasted the raw values into two new sheets (sheet x and sheet y). This made empty cells of the pivot table, that came about when corporations did not have activities in a municipality, take the form of nothing: "". Then in sheet x, I input in every cell (A2 for example) "=IF(Sheet_y!A2="";0;1)".

    This gave me a sheet x where for every corporation I had dummy variables for municipalities that took the form of 1 if there where activities in that municipality and 0 if they did not.

    Again, thanks a bunch!!

+ 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] Creating Dummy Variables using Excel
    By b0b020 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-11-2015, 09:23 AM
  2. [SOLVED] Replace cells and create dummy variables
    By slacknoise in forum Excel General
    Replies: 7
    Last Post: 06-18-2012, 02:40 PM
  3. dummy variables
    By Miloud in forum Excel General
    Replies: 2
    Last Post: 11-25-2009, 02:50 PM
  4. Generate lagged dummy variables
    By tianyi86 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-30-2009, 01:28 PM
  5. Dummy variables
    By Miloud in forum Excel General
    Replies: 2
    Last Post: 02-06-2009, 03:55 AM
  6. LINEST for dummy variables?
    By BlueFortyTwo in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-25-2007, 10:00 PM
  7. Insert dummy variables
    By Chris_t_2k5 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2006, 09:30 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