Create New Variables - Automatically Combine Categories - By Geography - World - To States/Provinces

From Q
Jump to navigation Jump to search

The features in Automatically Combine Categories > World are use to transform either Latitude/longitude coordinates or IP adresses into the geographic locations that correspond to this data. Such data can be transformed to the Country in which they are located, or the State or Province in which they are located.

Example

In this example, latitude and longitude coordinates have been transformed into the states in which they are located:

Usage

  1. Select a pair of latitude/longitude variables, or a single variable of IP adresses in the Variables and Questions tab.
  2. Select the desired option from Automate > Browse Online Library > Automatically Combine Categories > By Geography > World.
  3. To change how the categories are combined:
    1. Select the new variable or question in the Variables and Questions tab.
    2. Right-click and select Edit R Variable.
    3. Choose the desired options in the Inputs section on the right.
    4. Click Update R Variable.
  1. Select a pair of latitude/longitude variables, or a single variable of IP adresses under Data Sets containing geographic data.
  2. Click the + symbol to the right of the selected variable(s).
  3. Select the desired region then output type from Ready-Made New Variables > Automatically Combine Variables > By Geography.
  4. Choose options for the new variable in the Inputs section on the right of the screen.

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.

Customizing QScripts in Q4.11 and more recent versions

  • 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.

Customizing QScripts in older versions

  • Copy the JavaScript shown on this page.
  • Create a new text file, giving it a file extension of .QScript. See here for more information about how to do this.
  • Modify the JavaScript (see QScripts for more detail on this).
  • Run the file using Automate > Run QScript (Macro) from File.

JavaScript

includeWeb('QScript Functions for Geography');
reverseGeocode('Administrative region (state, province, etc.)');

See also