*! version 1.0 11 Oct 2024

Title

nca_random -- Generates random datapoints for y and x to be used for necessary condition analysis (NCA).

Syntax

nca_random
[ stub varname]
[,
options]

Required
n(#) Number of observations.

slopes(numlist) A list of slopes.

intercepts(numlist) A list of intercepts.

Optional
xdistribution(string) The distribution to be used to simulate the conditions.

ydistribution(string) The distribution to be used to simulate the outcomes.

clear Clear the current dataset

xmean(#) Mean of the condition variables to be generated.

xsd(#) Standard deviation of the condition variables to be generated.

ymean(#) Mean of the outcome variable to be generated.

ysd(#) Standard deviation of the outcome variable to be generated.

corner(#) Define which corner should be empty.

stub contain the prefix of all of the conditions to be generated. varname contains the name of the outcome variable to be generated. The default are x for stub and y for varname.

Description

Generates random datapoints for y and x to be used for necessary condition analysis (NCA). New variables are created in the current dataset.

Options

Main

n(#) The number of observations to be generated.

slopes(numlist) A list of real numbers containing the slopes. Users can choose to specify slopes with the same length as intercepts or to specify a single intercept, that will be replicated to match the length of intercepts. The number of conditions to be generated is equal to the length of slopes and intercepts.

intercepts(numlist) A list of real numbers containing the intercepts. Users can choose to specify intercepts with the same length as slopes or to specify a single intercept, that will be replicated to match the length of slopes. The number of conditions to be generated is equal to the length of slopes and intercepts.

xdistribution(string) the distribution to be used for the conditions. Specify uniform or normal. The default is uniform.

ydistribution(string) the distribution to be used for the outcome. Specify uniform or normal. The default is uniform.

clear Clears the current dataset.

xmean(#) Mean of the condition variables to be generated. The default is 0.5.

xsd(#) Standard deviation of the condition variables to be generated. The default is 0.2.

ymean(#) Mean of the outcome variable to be generated. The default is 0.5.

ysd(#) Standard deviation of the outcome variable to be generated. The default is 0.2.

corner(#) A positive integer (min=1 max=4) that defines which corner should be empty, default is 1 (upper left); 2 is upper right, 3 is bottom left and is 4 bottom right. Corners 1 and 4 require that all of the terms in slopes are positive. Corners 2 and 3 require negative slopes. See also the corner option in help nca.

Examples

Generate 1000 observations from the uniform distribution. y is bounded by the y=x line

. clear

. nca_random, n(1000) slopes(1) intercepts(0)

. twoway (scatter y x1) (function y=x), legend(off)

Generate 1000 observations from the uniform distribution. y is bounded from below by the y=1-x line.

. clear

. nca_random, n(1000) slopes(-1) intercepts(1) corner(3)

. twoway (scatter y x1) (function y=1-x), legend(off)

Generate 1000 observations. y is bounded by the y=x1 and y=0.1+0.5x2 line.

. clear

. nca_random, n(1000) slopes(1 0.5) intercepts(0 0.1)

. twoway (scatter y x1) (function y=x), legend(off)

. twoway (scatter y x2) (function y=0.1+0.5*x), legend(off)

Generate 1000 observations from the normal distribution (both x and y). The x has mean 0.4 and standard deviation equal to 0.1, y is bounded by the y=0.1+0.4x line and has 0.5 mean and 0.2 standard devation.

. clear

. nca_random, n(1000) xdistribution(normal) xmean(0.4) xsd(0.1) ydistribution(normal) intercepts(0.1) slopes(0.4)

. twoway (scatter y x1) (function y=0.4*x + 0.1 ), legend(off)

Author

Daniele Spinelli

Department of Statistics and Quantitative Methods

University of Milano-Bicocca

Milan, Italy

daniele.spinelli@unimib.it