This feature can be used to map an input variable containing European postcodes or place names (e.g. cities and towns) to a new variable containing the corresponding provinces.
Example
The following table contains the raw values from an input variable, labeled place, containing some locations in France in the left column. The right column contains the raw values of the output variable obtained from running this feature with place selected and selecting the proper Input data type and Output geographic type by editing the created R variable in the Variables and Questions tab.
Usage
In Q:
- Select a table showing the question you want to use to create combined categories, or a single variable in the Variables and Questions tab.
- Select the region the data comes from and the desired output type from Automate > Browse Online Library > Create New Variables > Automatically Combine Categories > By Geography > Europe > To Provinces.
- To change how the categories are combined:
- Select the new variable or question in the Variables and Questions tab.
- Right-click and select Edit R Variable.
- Choose the desired options in the Inputs section on the right.
- Click Update R Variable.
In Displayr:
- Select the variable you want to aggregate (for example, postcode) in the Data Sources tree.
- Hover and click + > Combine Categories > By Geography > Europe > To Provinces.
- To change how categories are combined (for example, you might decide that the counties aren't very useful and you would prefer regions instead).
- Select the new variable you created from the Data Sources tree.
- In Object Inspector, update Data > Output geographic type.
Note: If some entries in your input data could refer to any of several possible locations with the same name in the region, you will be shown additional prompts where you can supply a supplementary variable (e.g., containing state/province names for each place) to disambiguate the entries to their correct location. In some instances, you may see this prompt when your input data is actually a different type, such as counties or states, in which case you can select the proper type using the prompts.
Options
Variable The input variable containing geographic data to be combined into categories.
Combine by Use this control to toggle between the other methods for combining categories in the Combine Categories menu.
World region The geographic region that the input data/variable comes from.
Input data type The type of data/geographic unit, such as States, Postcodes, or Place (city, town, etc.), that the input variable contains.
Output geographic type The desired geographic unit to combine the input data into. Must be a larger type than Input data type; e.g., it is possible to map U.S. counties to U.S. states, but not the other way around.
Check spelling If this option is selected then approximate matching is performed using the Levenshtein distance, instead of requiring exact matching when looking up the input data values in the regional database.
Check neighboring region Select this option if the input data comes from more than one region than the one specified by World region. For example, with World region set to USA and this option selected, matches for the input data will also be looked for within Canada.
Supplementary variable Only shown when Input data type is Place (city, town, etc.). Use this dropbox to supply an additional variable with geographic info (such as state or region) to disambiguate place names in the input data that could represent multiple distinct locations in the region.
How to apply this QScript
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Click on the QScript when it appears in the QScripts and Rules section of the search results.
OR
- Select Automate > Browse Online Library.
- Select this QScript from the list.
Customizing the QScript
This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
- Press Edit a Copy (bottom-left corner of the preview).
- Modify the JavaScript (see QScripts for more detail on this).
- Either:
- Run the QScript, by pressing the blue triangle button.
- Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.
See also
- QScript for more general information about QScripts.
- QScript Examples Library for other examples.
- Online JavaScript Libraries for the libraries of functions that can be used when writing QScripts.
- QScript Reference for information about how QScript can manipulate the different elements of a project.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.