Home > Department of Geography and Environment > Who's who > profiles > Eric Neumayer > spdir - Stata ado-file: create directed dyad spatial effect variable

spdir - Stata ado-file: create directed dyad spatial effect variable

Eric Neumayer, LSE, Department of Geography and Environment

Thomas Plümper, Vienna University of Economics, Department of Socioeconomics

Syntax:

spir lagvar [if] [in],

weightvar(varname) source(varname) target(varname) link(options) [options]

options description:

time(varname)   contains the numeric time variable

exclusive exclusive directed dyad contagion

norowst spatial effect variable not row-standardized

nomerge no automatic merge of spatial effect variable into original dataset

sename(name) name to be given to created spatial effect variable

labelname(name) name of label given to spatial effect variable

filename(name) name of file to which spatial effect variable saved

Description:

spdir generates a directed dyad contagion spatial effect variable for analysis of spatial dependence in directed dyad data. It can create spatial effect variables for spatial lag, spatial-x and spatial error models. See Neumayer and Plümper (2010) for a discussion of the difference between monadic and dyadic data. See Plümper and Neumayer (2010, 2016) for a discussion of model specification in the analysis of spatial dependence.

Background information:

Dyadic data consists of observations in which two units form a pair (the dyad). In directed dyadic data, the interaction between two dyad members ij initiates with i and is directed toward j. In the directed dyad ij, unit i is called the source, while unit j is called the target of the interaction. It is different from the directed dyad ji, where, in contrast, unit j is the source and unit i is the target.

Normally, to generate spatial effect variables for dyadic data, one would need a so-called 4-adic dataset, which connects dyads with dyads. In many applications, such a dataset would be far too large to be handled by a standard PC. Fortunately, this ado-file can be used without such a dataset as it parses through a virtual 4-adic dataset generated from a standard dyadic dataset. Users should be warned, however, that it can take from several seconds to several minutes, hours or days to generate the spatial effect variable, depending on the size of the dyadic dataset.

To generate a spatial effect variable for directed dyadic data, one thus merely needs a directed dyadic dataset that contains at least four variables. One variable must identify the source unit i, while a second variable identifies the target unit j. Third, a variable to be spatially lagged (e.g., the directed dyadic dependent variable in spatial lag models). Fourth, a weighting or connectivity variable that links source unit i with target unit j. This weighting variable may or may not be directed. Users need not worry about creating weights linking source or target units with each other. The ado-file automatically virtually transforms the connectivity variable linking source unit i with target unit j such as, instead, to link source units with each other or target units with each other or simple combinations of the two (sum or product), depending on the choice of the link(options) option.  If the spatial effect variable is to be time-variant, then one additionally needs a fifth variable that identifies time.

Some users will prefer to work with two separate datasets: one used for the creation of the spatial effect variable, another one that is the actual estimation dataset, into which the spatial effect variable created from the other dataset needs to be merged by hand. In the case of two separate datasets, use the nomerge option. Some other users will prefer to work with one dataset only that contains all the variables needed for the actual estimations as well as all the variables needed for the creation of the spatial effect variable. In this case, use the default option, which merges the created spatial effect variable automatically into the original dataset, which is also the estimation dataset.

Arguments:

lagvar is the variable to be spatially lagged. It is the directed dyadic dependent variable in spatial lag models, a selected independent variable in spatial-x models and a saved regression residual in spatial error models.

weightvar(varname) is the weighting or connectivity variable linking source unit i with target unit j. It may or may not be directed.

source(varname) is the identifying variable of source unit i. It can be a numeric or string variable.

target(varname) is the identifying variable of target unit j. It can be a numeric or string variable. 

Options:

link(options) is required. The following options are allowed: ik, ki, im, mi, jm, mj, jk, kj.

Option ik requests that the virtually transformed weighting variable weightvar(varname) is to represent connectivity from source unit i to other source units k.
Option ki requests connectivity from other source units k to source unit i.
Option im requests connectivity from source unit i to target units m.
Option mi requests connectivity from target units m to source unit i.
Option jm requests connectivity from target unit j to other target units m.
Option mi requests connectivity from other target units m to target unit j.
Option jk requests connectivity from target unit j to source units k.
Option kj requests connectivity from source units m to target unit j.

Researchers can request the sum or product of any two of these connectivities by listing the first one, then either + or * and then the second link.  For example, option ik+jm requests that the weighting matrix represents the sum of connectivities invoked by ik and jm.  Option ik*kj requests that the weighting matrix represents the product of connectivities invoked by ik and kj. The order does not matter, i.e., option ik+jm is the same as option jm+ik. The same links cannot be combined with each other, i.e., ik+ik is not an allowed option. Which of the available options is appropriate depends on the specific hypothesis of spatial dependence to be tested.

timevar is an optional argument. If users wish to generate a time-varying spatial effect variable, then the numeric time variable must be stated here.

exclusive specifies that all dyads containing either i or j as either source or target are excluded from having a spatial effect on dyad ij.

norowst requests that the generated spatial effect variable is not row-standardized. See Plümper and Neumayer (2010, 2016) for an explanation and discussion of row-standardization. Row-standardization is the default option.

nomerge requests that the generated spatial effect variable is not automatically merged into the data set.

sename(name) names the generated spatial effect variable. In the default option, if the weighting matrix is row-standardized, then this variable is called SE_var_dirdyad_rowst for aggregate target contagion. If the weighting matrix is not row-standardized, then this variable is called SE_var_dirdyad_norowst. Any previously existing variable with the same name will be replaced. 

labelname(name) names the label of the generated spatial effect variable. The default label given is "Directed dyad contagion spatial effect variable".

filename(name) requests that a dataset containing the generated spatial effect variable is saved in the current working directory under the defined name. In the default option, if the weighting matrix is row-standardized, then a file is saved in the current working directory called SE_file_dirdyad_rowst. If the weighting matrix is not row-standardized, then the saved file is called SE_file_dirdyad_norowst. Any previously existing file with the same name will be replaced. 

Examples:

 spdir y, w(exports) s(source_country) t(target_country) link(ik)
        sename(se_dirdyad) filename(dirdyad_file)

 spdir y, w(exports) s(source_country) t(target_country) time(year)
        link(jm) norowst

 spdir y, w(exports) s(source_country) t(target_country) time(year)
        link(ik*jm) nomerge 

Example data-, do- and log-files:

(Data) (Do-file) (Log-file)

Installation:

Type "ssc install spdir" in Stata and follow instructions or download the ado- and help-file below into the relevant folder:

spdir.ado 

spdir.hlp

Questions and Errors:

Send any questions and report any errors to e.neumayer@lse.ac.uk.

References:

Neumayer, Eric and Plümper, Thomas. 2010. Spatial Effects in Dyadic Data, International Organization, 64 (1), pp. 145-165 (pdf)

Plümper, Thomas and Eric Neumayer. 2010. Model Specification in the Analysis of Spatial Dependence, European Journal of Political Research 49 (3), pp. 418-442  (pdf)

Neumayer, Eric and Thomas Plümper. 2016. W. Political Science Research and Methods, 4 (1), pp. 175-193 (pdf)

Share:Facebook|Twitter|LinkedIn|