
## Acessores

# $ahat
Output: 	series 

Must follow the estimation of a fixed-effect panel data model. Returns the estimates of individual fixed effects (per-unit intercepts). 

# $aic
Output: 	scalar 

Returns the Akaike Information Criterion for the last estimated model. 

# $bic
Output: 	scalar 

Returns Schwarz's Bayesian Information Criterion for the last estimated model. 

# $coeff
Output: 	scalar or matrix 
Argument: 	<@var="s">  (name of coefficient, optional)

The <@lit="$coeff"> accessor can be used in two ways: with no arguments, it returns a column vector containing the estimated coefficients for the last model. With the optional argument, it returns a scalar, which is the estimated parameter named <@var="s">. See also <@ref="$stderr">, <@ref="$vcv">. 

Example: 

<code>          
	  open bjg
	  arima 0 1 1 ; 0 1 1 ; lg 
	  b = $coeff 
	  macoef = $coeff(theta_1)
</code>

If the "model" in question is actually a system (a VAR or VECM, or system of simultaneous equations), <@lit="$coeff"> with no parameters returns the matrix of coefficients, one column per equation. 

# $compan
Output: 	matrix 

Must follow the estimation of a VAR or a VECM; returns the companion matrix. 

# $datatype
Output: 	scalar 

Returns an integer value representing the sort of dataset that is currently loaded: 0 = no data; 1 = cross-sectional (undated) data; 2 = time-series data; 3 = panel data. 

# $df
Output: 	scalar 

Returns the degrees of freedom of the last estimated model. 

# $ess
Output: 	scalar 

Returns the error sum of squares of the last estimated model. 

# $gmmcrit
Output: 	scalar 

Must follow a <@lit="gmm"> block. Returns the value of the objective function at its minimum. 

# $h
Output: 	series 

Must follow a <@lit="garch"> command. Returns the estimated conditional variance. 

# $hausman
Output: 	row vector 

Must follow a <@lit="tsls"> command. Returns a 1×3 vector, containing the value of the Hausman test statistic, the corresponding degrees of freedom and p-value, in this order. 

# $hqc
Output: 	scalar 

Returns the Hannan-Quinn Information Criterion for the last estimated model. 

# $jalpha
Output: 	matrix 

Must follow the estimation of a VECM, and returns the loadings matrix. It has as many rows as variables in the VECM and as many columns as the cointegration rank. 

# $jbeta
Output: 	matrix 

Must follow the estimation of a VECM, and returns the cointegration matrix. It has as many rows as variables in the VECM (plus the number of exogenous variables that are restricted to the cointegration space, if any), and as many columns as the cointegration rank. 

# $jvbeta
Output: 	square matrix 

Must follow the estimation of a VECM, and returns the estimated covariance matrix for the elements of the cointegration vectors. 

In the case of unrestricted estimation, it has a number of rows equal to the unrestricted elements of the cointegration space after the Phillips normalization. If, however, a restricted system is estimated via the <@lit="restrict"> command with the <@lit="--full"> option, a singular matrix with <@itl="(n+m)r"> rows will be returned (<@itl="n"> being the number of endogenous variables, <@itl="m"> the number of exogenous variables that are restricted to the cointegration space, and <@itl="r"> the cointegration rank). 

Example: the code 

<code>          
	  open denmark.gdt
	  vecm 2 1 LRM LRY IBO IDE --rc --seasonals -q
	  s0 = $jvbeta

	  restrict --full
	  b[1,1] = 1
	  b[1,2] = -1
	  b[1,3] + b[1,4] = 0
	  end restrict
	  s1 = $jvbeta

	  print s0
	  print s1
</code>

produces the following output. 

<code>          
	  s0 (4 x 4)

	    0.019751     0.029816  -0.00044837     -0.12227 
	    0.029816      0.31005     -0.45823     -0.18526 
	 -0.00044837     -0.45823       1.2169    -0.035437 
	    -0.12227     -0.18526    -0.035437      0.76062 

	  s1 (5 x 5)

	  0.0000       0.0000       0.0000       0.0000       0.0000 
	  0.0000       0.0000       0.0000       0.0000       0.0000 
	  0.0000       0.0000      0.27398     -0.27398    -0.019059 
	  0.0000       0.0000     -0.27398      0.27398     0.019059 
	  0.0000       0.0000    -0.019059     0.019059    0.0014180
</code>

# $lnl
Output: 	scalar 

Returns the log-likelihood for the last estimated model (where applicable). 

# $ncoeff
Output: 	scalar 

Total number of coefficients estimated in the last model. 

# $nobs
Output: 	scalar 

Returns the number of observations in the currently selected sample. 

# $nvars
Output: 	scalar 

Returns the number of variables in the dataset (including the constant). 

# $pd
Output: 	scalar 

Returns the frequency or periodicity of the data (e.g. 4 for quarterly data). 

# $pvalue
Output: 	scalar 

Returns the p-value of the test statistic that was generated by the last explicit hypothesis-testing command, if any (e.g. <@lit="chow">). See <@pdf="the Gretl User's Guide"> for details. See also <@ref="$test">. 

# $rho
Output: 	scalar 
Argument: 	<@var="n">  (scalar, optional)

Without arguments, returns the first-order autoregressive coefficient for the residuals of the last model. After estimating a model via the <@lit="ar"> command, the syntax <@lit="$rho(n)"> returns the corresponding estimate of ρ(<@itl="n">). 

# $rsq
Output: 	scalar 

Returns the unadjusted <@itl="R"><@sup="2"> from the last estimated model. 

# $sample
Output: 	series 

Must follow estimation of a single-equation model. Returns a dummy series with value 1 for observations used in estimation, 0 for observations within the currently defined sample range but not used (presumably because of missing values), and NA for observations outside of the current range. 

If you wish to compute statistics based on the sample that was used for a given model, you can do, for example: 

<code>          
	  ols y 0 xlist
	  genr sdum = $sample
	  smpl sdum --dummy
</code>

# $sargan
Output: 	row vector 

Must follow a <@lit="tsls"> command. Returns a 1×3 vector, containing the value of the Sargan over-identification test statistic, the corresponding degrees of freedom and p-value, in this order. 

# $sigma
Output: 	scalar 

Returns the standard error of the residuals (or Standard Error of Estimate) from the last model. 

# $stderr
Output: 	scalar or matrix 
Argument: 	<@var="s">  (name of coefficient, optional)

The <@lit="$stderr"> accessor can be used in two ways: with no arguments, it returns a column vector containing the standard error of the coefficients for the last model. With the optional argument, it returns a scalar, namely the standard error of the parameter called <@var="s">. See also <@ref="$coeff">, <@ref="$vcv">. 

# $stopwatch
Output: 	scalar 

Must be preceded by <@lit="set stopwatch">, which activates the measurement of CPU time. The first use of this accessor yields the seconds of CPU time that have elapsed since the <@lit="set stopwatch"> command. At each access the clock is reset, so subsequent uses of <@lit="$stopwatch"> yield the seconds of CPU time since the previous access. 

# $T
Output: 	scalar 

Number of observations used in estimating the last model. 

# $t1
Output: 	scalar 

The 1-based index of the first observation in the currently selected sample. 

# $t2
Output: 	scalar 

The 1-based index of the last observation in the currently selected sample. 

# $test
Output: 	scalar 

Returns the value of the test statistic that was generated by the last explicit hypothesis-testing command, if any (e.g. <@lit="chow">). See <@pdf="the Gretl User's Guide"> for details. See also <@ref="$pvalue">. 

# $trsq
Output: 	scalar 

Returns <@itl="TR"><@sup="2"> (sample size times R-squared) from the last model. 

# $uhat
Output: 	series 

Returns the residuals from the last model. This may have different meanings for different estimators. For example, after an ARMA estimation <@lit="$uhat"> will contain the one-step-ahead forecast error; after a probit model, it will contain the generalized residuals. 

If the "model" in question is actually a system (a VAR or VECM, or system of simultaneous equations), <@lit="$uhat"> with no parameters retrieves the matrix of residuals, one column per equation. 

# $unit
Output: 	series 

Valid for panel datasets only. Returns a series with value 1 for all observations on the first unit or group, 2 for observations on the second unit, and so on. 

# $vcv
Output: 	scalar or matrix 
Arguments:	<@var="s1">  (name of coefficient, optional)
		<@var="s2">  (name of coefficient, optional)

The <@lit="$stderr"> accessor can be used in two ways: with no arguments, it returns a square matrix containing the estimated covariance matrix for the coefficients of the last model. With the optional arguments, it returns a scalar, which is the estimated covariance between the parameters named <@var="s1"> and <@var="s2">. See also <@ref="$coeff">, <@ref="$stderr">. 

If the "model" in question is actually a system (a VAR or VECM, or system of simultaneous equations), <@lit="$vcv"> with no parameters returns the cross-equation covariance matrix. 

# $version
Output: 	scalar 

Returns an integer value that codes for the program version. The gretl version string takes the form <@lit="x.y.z"> (for example, 1.7.6). The return value from this accessor is formed as <@lit="10000*x + 100*y + z">, so that 1.7.6 translates as 10706. 

# $windows
Output: 	scalar 

Returns 1 if gretl is running on MS Windows, otherwise 0. By conditioning on the value of this variable you can write shell calls that are portable across different operating systems. 

Also see the <@xrf="shell"> command. 

# $xlist
Output: 	list 

Returns the list of regressors from the last model (for single-equation models only). 

# $yhat
Output: 	series 

Returns the fitted values from the last regression. 

## Funcoes

# abs
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Absolute value. 

# acos
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

The arc cosine of <@var="x">, that is, the value whose cosine is <@var="x">. The result is in radians; the input should be in the range –1 to 1. 

# asin
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

The arc sine of <@var="x">, that is, the value whose sine is <@var="x">. The result is in radians; the input should be in the range –1 to 1. 

# atan
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

The arc tangent of <@var="x">, that is, the value whose tangent is <@var="x">. The result is in radians. 

# BFGSmax
Output: 	scalar 
Arguments:	<@var="b">  (vector)
		<@var="s">  (string)

Numerical maximization via the method of Broyden, Fletcher, Goldfarb and Shanno. The vector <@var="b"> should hold the initial values of a set of parameters, and the string <@var="s"> should specify a call to a function that calculates the (scalar) criterion to be maximized, given the current parameter values and any other relevant data. If the object is in fact minimization, this function should return the negative of the criterion. On successful completion, <@lit="BFGSmax"> returns the maximized value of the criterion, and <@var="b"> holds the parameter values which produce the maximum. 

For more details and examples see the chapter on special functions in <@lit="genr"> in <@pdf="the Gretl User's Guide">. See also <@ref="fdjac">. 

# bkfilt
Output: 	series 
Argument: 	<@var="y">  (series)

Extracts the cyclical component of series <@var="y"> via the Baxter–King bandpass filter, a two-sided symmetric filter. See <@pdf="the Gretl User's Guide"> for details. See also <@ref="hpfilt">. 

# cdemean
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Centers the columns of matrix <@var="X"> around their means. 

# cdf
Output: 	same type as input 
Arguments:	<@var="c">  (character)
		<@var="…">  (see below)
		<@var="x">  (scalar, series or matrix)
Examples: 	<@lit="p1 = cdf(N, -2.5)">
		<@lit="p2 = cdf(X, 3, 5.67)">
		<@lit="p3 = cdf(D, 0.25, -1, 1)">

Cumulative distribution function calculator. Returns <@itl="P(X < x)">, where the distribution <@itl="X"> is determined by the character <@var="c">. Between the arguments <@var="c"> and <@var="x">, zero or more additional arguments are required to specify the parameters of the distribution, as follows. 

<indent>
• Standard normal (c = z, n, or N): no extra arguments 
</indent>

<indent>
• Bivariate normal (D): correlation coefficient 
</indent>

<indent>
• Student's t (t): degrees of freedom 
</indent>

<indent>
• Chi square (c, x, or X): degrees of freedom 
</indent>

<indent>
• Snedecor's F (f or F): df (num.); df (den.) 
</indent>

<indent>
• Gamma (g or G): shape; scale 
</indent>

<indent>
• Binomial (b or B): probability; number of trials 
</indent>

<indent>
• Poisson (p or P): Mean 
</indent>

<indent>
• Weibull (w or W): shape; scale 
</indent>

Note that most cases have aliases to help memorizing the codes. The bivariate normal case is special: the syntax is <@lit="x = cdf(D, rho, z1, z2)"> where <@lit="rho"> is the correlation between the variables <@lit="z1"> and <@lit="z2">. 

See also <@ref="pdf">, <@ref="critical">, <@ref="invcdf">, <@ref="pvalue">. 

# cdiv
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="Y">  (matrix)

Complex division. The two arguments must have the same number of rows, <@itl="n">, and either one or two columns. The first column contains the real part and the second (if present) the imaginary part. The return value is an <@itl="n">×<@itl="2"> matrix or, if the result has no imaginary part, an <@itl="n">-vector. See also <@ref="cmult">. 

# ceil
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Ceiling function: returns the smallest integer greater than or equal to <@var="x">. See also <@ref="floor">, <@ref="int">. 

# cholesky
Output: 	square matrix 
Argument: 	<@var="A">  (square matrix)

Peforms a Cholesky decomposition of the matrix <@var="A">, which is assumed to be symmetric and positive definite. The result is a lower-triangular matrix <@itl="K"> which satisfies <@itl="A = KK'">. The function will fail if <@var="A"> is not symmetric or not positive definite. 

# cmult
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="Y">  (matrix)

Complex multiplication. The two arguments must have the same number of rows, <@itl="n">, and either one or two columns. The first column contains the real part and the second (if present) the imaginary part. The return value is an <@itl="n">×<@itl="2"> matrix, or, if the result has no imaginary part, an <@itl="n">-vector. See also <@ref="cdiv">. 

# cnorm
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the cumulative distribution function for a standard normal. See also <@ref="dnorm">, <@ref="qnorm">. 

# colnames
Output: 	scalar 
Arguments:	<@var="M">  (matrix)
		<@var="s">  (named list or string)

Attaches names to the columns of the <@itl="T">×<@itl="k"> matrix <@var="M">. If <@var="s"> is a named list, the column names are copied from the names of the variables; the list must have <@itl="k"> members. If <@var="s"> is a string, it should contain <@itl="k"> space-separated sub-strings. The return value is 0 on successful completion, non-zero on error. 

# cols
Output: 	scalar 
Argument: 	<@var="X">  (matrix)

The number of columns of <@var="X">. See also <@ref="mshape">, <@ref="rows">, <@ref="unvech">, <@ref="vec">, <@ref="vech">. 

# corr
Output: 	scalar 
Arguments:	<@var="y1">  (series)
		<@var="y2">  (series)

Computes the correlation coefficient between <@var="y1"> and <@var="y2">. See also <@ref="cov">, <@ref="mcov">, <@ref="mcorr">. 

# cos
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Cosine. 

# cov
Output: 	scalar 
Arguments:	<@var="y1">  (series)
		<@var="y2">  (series)

Computes the covariance between <@var="y1"> and <@var="y2">. See also <@ref="corr">, <@ref="mcov">, <@ref="mcorr">. 

# critical
Output: 	same type as input 
Arguments:	<@var="c">  (character)
		<@var="…">  (see below)
		<@var="p">  (scalar, series or matrix)
Examples: 	<@lit="c1 = critical(t, 20, 0.025)">
		<@lit="c2 = critical(F, 4, 48, 0.05)">

Critical value calculator. Returns <@itl="x"> such that <@itl="P(X > x) = p">, where the distribution <@itl="X"> is determined by the character <@var="c">. Between the arguments <@var="c"> and <@var="p">, zero or more additional arguments are required to specify the parameters of the distribution, as follows. 

<indent>
• Standard normal (c = z, n, or N): no extra arguments 
</indent>

<indent>
• Student's t (t): degrees of freedom 
</indent>

<indent>
• Chi square (c, x, or X): degrees of freedom 
</indent>

<indent>
• Snedecor's F (f or F): df (num.); df (den.) 
</indent>

<indent>
• Binomial (b or B): probability; trials 
</indent>

See also <@ref="cdf">, <@ref="invcdf">, <@ref="pvalue">. 

# cum
Output: 	same type as input 
Argument: 	<@var="x">  (series or matrix)

Cumulates <@var="x">. When <@var="x"> is a series, produces a series <@itl="y"> each of whose elements is the sum of the values of <@var="x"> to date; the starting point of the summation is the first non-missing observation in the currently selected sample. When <@var="x"> is a matrix, its elements are cumulated by columns. 

See also <@ref="diff">. 

# det
Output: 	scalar 
Argument: 	<@var="A">  (square matrix)

Returns the determinant of <@var="A">, computed via the LU factorization. See also <@ref="ldet">, <@ref="rcond">. 

# diag
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Returns the principal diagonal of <@var="X"> in a column vector. Note: if <@var="X"> is an <@itl="m">×<@itl="n"> marix, the number of elements of the output vector is min(<@itl="m">, <@itl="n">). See also <@ref="tr">. 

# diff
Output: 	same type as input 
Argument: 	<@var="y">  (series, matrix or list)

Computes first differences. If <@var="y"> is a series, or a list of series, starting values are set to <@lit="NA">. If <@var="y"> is a matrix, differencing is done by columns and starting values are set to 0. 

When a list is returned, the individual variables are automatically named according to the template <@lit="d_"><@var="varname"> where <@var="varname"> is the name of the original series. The name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

See also <@ref="cum">, <@ref="ldiff">, <@ref="sdiff">. 

# dnorm
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the density of the standard normal distribution at <@var="x">. To get the density for a non-standard normal distribution at <@itl="x">, pass the <@itl="z">-score of <@itl="x"> to the <@lit="dnorm"> function and multiply the result by the Jacobian of the <@itl="z"> transformation, namely 1 over σ, as illustrated below: 

<code>          
	  mu = 100
	  sigma = 5
	  x = 109
	  fx = (1/sigma) * dnorm((x-mu)/sigma)
</code>

See also <@ref="cnorm">, <@ref="qnorm">. 

# dsort
Output: 	same type as input 
Argument: 	<@var="x">  (series or vector)

Sorts <@var="x"> in descending order, skipping observations with missing values when <@var="x"> is a series. See also <@ref="sort">, <@ref="values">. 

# dummify
Output: 	list 
Argument: 	<@var="x">  (series or list)

The argument <@var="x"> should be a discrete series, or list of such series. This function creates a set of dummy variables coding for the distinct values in the series; the smallest value is taken as the omitted category and is not explicitly represented. 

The generated variables are automatically named according to the template <@lit="D"><@var="varname"><@lit="_"><@var="i"> where <@var="varname"> is the name of the original series and <@var="i"> is a 1-based index. The original portion of the name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

# eigengen
Output: 	matrix 
Arguments:	<@var="A">  (square matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)

Computes the eigenvalues, and optionally the right eigenvectors, of the <@itl="n">×<@itl="n"> matrix <@var="A">. If all the eigenvalues are real, an <@itl="n">×<@itl="1"> matrix is returned; otherwise, the result is an <@itl="n">×<@itl="2"> matrix, the first column holding the real components and the second column the imaginary components. 

The second argument must be either the name of an existing matrix preceded by <@lit="&"> (to indicate the "address" of the matrix in question), in which case an auxiliary result is written to that matrix, or the keyword <@lit="null">, in which case the auxiliary result is not produced. 

If a non-null second argument is given, the specified matrix will be over-written with the auxiliary result. (It is not required that the existing matrix be of the right dimensions to receive the result.) It will be organized as follows: 

<indent>
• If the <@itl="i">-th eigenvalue is real, the <@itl="i">-th column of <@itl="U"> will contain the corresponding eigenvector; 
</indent>

<indent>
• If the <@itl="i">-th eigenvalue is complex, the <@itl="i">-th column of <@var="U"> will contain the real part of the corresponding eigenvector and the next column the imaginary part. The eigenvector for the conjugate eigenvalue is the conjugate of the eigenvector. 
</indent>

In other words, the eigenvectors are stored in the same order as the eigenvalues, but the real eigenvectors occupy one column, whereas complex eigenvectors take two (the real part comes first); the total number of columns is still <@itl="n">, because the conjugate eigenvector is skipped. 

See also <@ref="eigensym">, <@ref="qrdecomp">, <@ref="svd">. 

# eigensym
Output: 	column vector 
Arguments:	<@var="A">  (square matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)

Computes the eigenvalues, and optionally the right eigenvectors, of the <@itl="n">×<@itl="n"> symmetrix matrix <@var="A">; the second argument must be either the name of an existing matrix preceded by <@lit="&"> (to indicate the "address" of the matrix in question), in which case an auxiliary result is written to that matrix, or the keyword <@lit="null">, in which case the auxiliary result is not produced. 

If the second argument is not <@lit="null">, the specified matrix will be over-written with the auxiliary result. (It is not required that the existing matrix be of the right dimensions to receive the result.) 

See also <@ref="eigengen">, <@ref="qrdecomp">, <@ref="svd">. 

# exp
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Exponential. Note: in case of matrices, the function acts element by element. For the matrix exponential function, see <@ref="mexp">. 

# fdjac
Output: 	matrix 
Arguments:	<@var="b">  (column vector)
		<@var="s">  (string)

Calculates the (forward-difference approximation to the) Jacobian associated with the vector <@var="b"> and the transformation function defined by the function call in the string <@var="s">. For more details and examples see the chapter on special functions in <@lit="genr"> in <@pdf="the Gretl User's Guide">. 

See also <@ref="BFGSmax">. 

# fft
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Discrete real Fourier transform. If the input matrix <@var="X"> has <@itl="n"> columns, the output has 2<@itl="n"> columns, where the real parts are stored in the odd columns and the complex parts in the even ones. 

Should it be necessary to compute the Fourier transform on several vectors with the same number of elements, it is numerically more efficient to group them into a matrix rather than invoking <@lit="fft"> for each vector separately. See also <@ref="ffti">. 

# ffti
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Inverse discrete real Fourier transform. It is assumed that <@var="X"> contains <@itl="n"> complex column vectors, with the real part in the odd columns and the imaginary part in the even ones, so the total number of columns should be 2<@itl="n">. A matrix with <@itl="n"> columns is returned. 

Should it be necessary to compute the inverse Fourier transform on several vectors with the same number of elements, it is numerically more efficient to group them into a matrix rather than invoking <@lit="ffti"> for each vector separately. See also <@ref="fft">. 

# firstobs
Output: 	scalar 
Argument: 	<@var="y">  (series)

First non-missing observation for the variable <@var="y">. Note that if some form of subsampling is in effect, the value returned may be smaller than the dollar variable <@ref="$t1">. See also <@ref="lastobs">. 

# floor
Output: 	same type as input 
Argument: 	<@var="y">  (scalar, series or matrix)

Floor function: returns the greatest integer less than or equal to <@var="x">. Note: <@ref="int"> and <@lit="floor"> differ in their effect for negative arguments: <@lit="int(-3.5)"> gives –3, while <@lit="floor(-3.5)"> gives –4. 

# fracdiff
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="d">  (scalar)

Returns the fractional difference of order <@var="d"> for the series <@var="y">. 

Note that in theory fractional differentiation is an infinitely long filter. In practice, presample values of <@itl="y"><@sub="t"> are assumed to be zero. 

# gammafun
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the gamma function of <@var="x">. 

# genpois
Output: 	series 
Argument: 	<@var="μ">  (scalar or series)

Generates a series of Poisson pseudo-random variates. If μ is a scalar, all the elements are drawn from the same distribution; if μ is a series, the appropriate value μ<@sub="t"> is used at each observation. 

See also <@ref="randgen">, <@ref="normal">, <@ref="uniform">, <@ref="mnormal">, <@ref="muniform">. 

# getenv
Output: 	string 
Argument: 	<@var="s">  (string)

If an environment variable by the name of <@var="s"> is defined, returns the value of that variable, otherwise returns an empty string. 

# gini
Output: 	scalar 
Argument: 	<@var="y">  (series)

Returns Gini's inequality index for the series <@var="y">. 

# ginv
Output: 	matrix 
Argument: 	<@var="A">  (matrix)

Returns <@itl="A"><@sup="+">, the Moore–Penrose or generalized inverse of <@var="A">, computed via the singular value decomposition. 

This matrix has the properties <@itl="A"> <@itl="A"><@sup="+"> <@itl="A"> = <@itl="A"> and <@itl="A"><@sup="+"> <@itl="A"> <@itl="A"><@sup="+"> = <@itl="A"><@sup="+"> . Moreover, the products <@itl="A"> <@itl="A"><@sup="+"> and <@itl="A"><@sup="+"> <@itl="A"> are symmetric by construction. 

See also <@ref="inv">, <@ref="svd">. 

# hpfilt
Output: 	series 
Argument: 	<@var="y">  (series)

Returns the cycle from the Hodrick–Prescott filter applied to series <@var="y">. See <@pdf="the Gretl User's Guide"> for details. See also <@ref="bkfilt">. 

# I
Output: 	square matrix 
Argument: 	<@var="n">  (scalar)

Returns an identity matrix with <@var="n"> rows and columns. 

# imaxc
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the row indices of the maxima of the columns of <@var="X">. 

See also <@ref="imaxr">, <@ref="iminc">, <@ref="maxc">. 

# imaxr
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the column indices of the maxima of the rows of <@var="X">. 

See also <@ref="imaxc">, <@ref="iminr">, <@ref="maxr">. 

# iminc
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the row indices of the minima of the columns of <@itl="X">. 

See also <@ref="iminr">, <@ref="imaxc">, <@ref="minc">. 

# iminr
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the column indices of the mimima of the rows of <@itl="X">. 

See also <@ref="iminc">, <@ref="imaxr">, <@ref="minr">. 

# infnorm
Output: 	scalar 
Argument: 	<@var="X">  (matrix)

Returns the infinity-norm of <@var="X">, that is, the maximum across the rows of <@var="X"> of the sum of absolute values of the row elements. 

See also <@ref="onenorm">. 

# int
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Truncates the fractional part of <@var="x">. Note: <@lit="int"> and <@ref="floor"> differ in their effect for negative arguments: <@lit="int(-3.5)"> gives –3, while <@lit="floor(-3.5)"> gives –4. See also <@ref="ceil">. 

# inv
Output: 	matrix 
Argument: 	<@var="A">  (square matrix)

Returns the inverse of <@var="A">. If <@var="A"> is singular or not square, an error message is produced and nothing is returned. Note that gretl checks automatically the structure of <@var="A"> and uses the most efficient numerical procedure to perform the inversion. 

The matrix types gretl checks for are: identity; diagonal; symmetric and positive definite; symmetric but not positive definite; and triangular. 

See also <@ref="ginv">, <@ref="invpd">. 

# invcdf
Output: 	same type as input 
Arguments:	<@var="c">  (character)
		<@var="…">  (see below)
		<@var="p">  (scalar, series or matrix)

Inverse cumulative distribution function calculator. Returns <@itl="x"> such that <@itl="P(X < x) = p">, where the distribution <@itl="X"> is determined by the character <@var="c">; Between the arguments <@var="c"> and <@var="p">, zero or more additional arguments are required to specify the parameters of the distribution, as follows. 

<indent>
• Standard normal (c = z, n, or N): no extra arguments 
</indent>

<indent>
• Student's t (t): degrees of freedom 
</indent>

<indent>
• Chi square (c, x, or X): degrees of freedom 
</indent>

<indent>
• Snedecor's F (f or F): df (num.); df (den.) 
</indent>

<indent>
• Binomial (b or B): probability; trials 
</indent>

See also <@ref="cdf">, <@ref="critical">, <@ref="pvalue">. 

# invpd
Output: 	square matrix 
Argument: 	<@var="A">  (symmetric matrix)

Returns the inverse of the symmetric, positive definite matrix <@var="A">. This function is slightly faster than <@ref="inv"> for large matrices, since no check for symmetry is performed; for that reason it should be used with care. 

# islist
Output: 	scalar 
Argument: 	<@var="s">  (string)

Returns 1 if <@var="s"> is the identifier for a currently defined list, otherwise 0. See also <@ref="isnull">, <@ref="isseries">, <@ref="isstring">. 

# isnull
Output: 	scalar 
Argument: 	<@var="s">  (string)

Returns 0 if <@var="s"> is the identifier for a currently defined object, be it a scalar, a series, a matrix, list or string; otherwise returns 1. See also <@ref="islist">, <@ref="isseries">, <@ref="isstring">. 

# isseries
Output: 	scalar 
Argument: 	<@var="s">  (string)

Returns 1 if <@var="s"> is the identifier for a currently defined series, otherwise 0. See also <@ref="islist">, <@ref="isnull">, <@ref="isstring">. 

# isstring
Output: 	scalar 
Argument: 	<@var="s">  (string)

Returns 1 if <@itl="s"> is the identifier for a currently defined string, otherwise 0. See also <@ref="islist">, <@ref="isnull">, <@ref="isseries">. 

# lags
Output: 	list 
Arguments:	<@var="p">  (scalar)
		<@var="y">  (series or list)

Generates lags 1 to <@var="p"> of the series <@var="y">, or if <@var="y"> is a list, of all variables in the list. If <@var="p"> = 0, the maximum lag defaults to the periodicity of the data; otherwise <@var="p"> must be positive. 

The generated variables are automatically named according to the template <@var="varname"><@lit="_"><@var="i"> where <@var="varname"> is the name of the original series and <@var="i"> is the specific lag. The original portion of the name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

# lastobs
Output: 	scalar 
Argument: 	<@var="y">  (series)

Last non-missing observation for the variable <@var="y">. Note that if some form of subsampling is in effect, the value returned may be larger than the dollar variable <@ref="$t2">. See also <@ref="firstobs">. 

# ldet
Output: 	scalar 
Argument: 	<@var="A">  (square matrix)

Returns the natural log of the determinant of <@itl="A">, computed via the LU factorization. See also <@ref="det">, <@ref="rcond">. 

# ldiff
Output: 	same type as input 
Argument: 	<@var="y">  (series or list)

Computes log differences; starting values are set to <@lit="NA">. 

When a list is returned, the individual variables are automatically named according to the template <@lit="ld_"><@var="varname"> where <@var="varname"> is the name of the original series. The name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

See also <@ref="diff">, <@ref="sdiff">. 

# lincomb
Output: 	series 
Arguments:	<@var="L">  (list)
		<@var="b">  (vector)

Computes a new series as a linear combination of the series in the list <@var="L">. The coefficients are given by the vector <@var="b">, which must have length equal to the number of series in <@var="L">. 

See also <@ref="wmean">. 

# ljungbox
Output: 	scalar 
Arguments:	<@var="y">  (series)
		<@var="p">  (scalar)

Computes the Ljung–Box Q' statistic for the series <@var="y"> using lag order <@var="p">. The currently defined sample range is used. The lag order must be greater than or equal to 1 and less than the number of available observations. 

This statistic may be referred to the chi-square distribution with <@var="p"> degrees of freedom as a test of the null hypothesis that the series <@var="y"> is serially independent. See also <@ref="pvalue">. 

# lngamma
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Log of the gamma function of <@var="x">. 

# log
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series, matrix or list)

Natural logarithm; produces <@lit="NA"> for non-positive values. Note: <@lit="ln"> is an acceptable alias for <@lit="log">. 

When a list is returned, the individual variables are automatically named according to the template <@lit="l_"><@var="varname"> where <@var="varname"> is the name of the original series. The name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

# log10
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Base-10 logarithm; produces <@lit="NA"> for non-positive values. 

# log2
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Base-2 logarithm; produces <@lit="NA"> for non-positive values. 

# lower
Output: 	square matrix 
Argument: 	<@var="A">  (matrix)

Returns an <@itl="n">×<@itl="n"> lower triangular matrix: the elements on and below the diagonal are equal to the corresponding elements of <@var="A">; the remaining elements are zero. 

See also <@ref="upper">. 

# lrvar
Output: 	scalar 
Arguments:	<@var="y">  (series)
		<@var="k">  (scalar)

Returns the long-run variance of <@var="y">, calculated using a Bartlett kernel with window size <@var="k">. If <@var="k"> is negative, <@lit="int(T^(1/3))"> is used. 

# makemask
Output: 	column vector 
Argument: 	<@var="y">  (series)

Produces a column vector containing the observation numbers corresponding to the non-zero entries in the series <@var="y">. This function is typically useful for filtering out rows of a matrix built from data series. 

# max
Output: 	scalar or series 
Argument: 	<@var="y">  (series or list)

If the argument <@var="y"> is a series, returns the (scalar) maximum of the non-missing observations in the series. If the argument is a list, returns a series each of whose elements is the maximum of the values of the listed variables at the given observation. 

# maxc
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the maxima of the columns of <@var="X">. 

See also <@ref="imaxc">, <@ref="maxr">, <@ref="minc">. 

# maxr
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the maxima of the rows of <@var="X">. 

See also <@ref="imaxc">, <@ref="maxc">, <@ref="minr">. 

# mcorr
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Computes a correlation matrix treating each column of <@var="X"> as a variable. See also <@ref="corr">, <@ref="cov">, <@ref="mcov">. 

# mcov
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Computes a covariance matrix treating each column of <@var="X"> as a variable. See also <@ref="corr">, <@ref="cov">, <@ref="mcorr">. 

# mean
Output: 	scalar or series 
Argument: 	<@var="x">  (series or list)

If <@var="x"> is a series, returns the (scalar) sample mean, skipping any missing observations. 

If <@var="x"> is a list, returns a series <@itl="y"> such that <@itl="y"><@sub="t"> is the mean of the values of the variables in the list at observation <@itl="t">, or <@lit="NA"> if there are any missing values at <@itl="t">. 

# meanc
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the means of the columns of <@var="X">. See also <@ref="meanr">, <@ref="sumc">, <@ref="sdc">. 

# meanr
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the means of the rows of <@var="X">. See also <@ref="meanc">, <@ref="sumr">. 

# median
Output: 	scalar 
Argument: 	<@var="y">  (series)

The median of the non-missing observations in series <@var="y">. See also <@ref="quantile">. 

# mexp
Output: 	square matrix 
Argument: 	<@var="A">  (square matrix)

Computes the matrix exponential of <@var="A">, using algorithm 11.3.1 from Golub and Van Loan (1996). 

# min
Output: 	scalar or series 
Argument: 	<@var="y">  (series or list)

If the argument <@var="y"> is a series, returns the (scalar) minimum of the non-missing observations in the series. If the argument is a list, returns a series each of whose elements is the minimum of the values of the listed variables at the given observation. 

# minc
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the minima of the columns of <@var="X">. 

See also <@ref="iminc">, <@ref="maxc">, <@ref="minr">. 

# minr
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the minima of the rows of <@var="X">. 

See also <@ref="iminr">, <@ref="maxr">, <@ref="minc">. 

# missing
Output: 	same type as input 
Argument: 	<@var="x">  (scalar or series)

Returns a binary variable holding 1 if <@var="x"> is <@lit="NA">. If <@var="x"> is a series, the comparison is done element by element. See also <@ref="misszero">, <@ref="ok">, <@ref="zeromiss">. 

# misszero
Output: 	same type as input 
Argument: 	<@var="x">  (scalar or series)

Converts <@lit="NA">s to zeros. If <@var="x"> is a series, the conversion is done element by element. See also <@ref="missing">, <@ref="ok">, <@ref="zeromiss">. 

# mlag
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="p">  (scalar)

For <@var="p"> > 0, returns a matrix in which the columns of <@var="X"> are shifted down by <@var="p"> rows and the first <@var="p"> rows are filled with zeros. If <@var="p"> is a negative number, <@var="X"> is shifted up and the last rows are filled with zeros. 

# mnormal
Output: 	matrix 
Arguments:	<@var="r">  (scalar)
		<@var="c">  (scalar)

Returns a matrix with <@var="r"> rows and <@var="c"> columns, filled with standard normal pseudo-random variates. See also <@ref="normal">, <@ref="muniform">. 

# mols
Output: 	matrix 
Arguments:	<@var="Y">  (matrix)
		<@var="X">  (matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)

Returns a <@itl="k">×<@itl="n"> matrix of parameter estimates obtained by OLS regression of the <@itl="T">×<@itl="n"> matrix <@var="Y"> on the <@itl="T">×<@itl="k"> matrix <@var="X">. The Cholesky decomposition is used. If the third argument is not <@lit="null">, the <@itl="T">×<@itl="n"> matrix <@var="U"> will contain the residuals. 

# movavg
Output: 	series 
Arguments:	<@var="x">  (series)
		<@var="p">  (scalar)

Computes the <@var="p">-term moving average for the series <@var="x">, that is the average of x(t) to x(t-p+1). 

Note that the result is not centered. If you want a centered moving average, you can use the lead operator on the returned series. Example: 

<code>          
	    tmp = movavg(x,3)
	    y = tmp(+1)
</code>

# mread
Output: 	matrix 
Argument: 	<@var="s">  (string)

Reads a matrix from a text file. The string <@var="s"> must contain the name of the (plain text) file from which the matrix is to be read. The file in question must conform to the following rules: 

<indent>
• The columns must be separated by spaces or tab characters. 
</indent>

<indent>
• The decimal separator must be the dot character, "<@lit=".">". 
</indent>

<indent>
• The first line in the file must contain two integers, separated by a space or a tab, indicating the number of rows and columns, respectively. 
</indent>

Should an error occur (such as the file being badly formatted or inaccessible), an empty matrix is returned. 

See also <@ref="mwrite">. 

# mshape
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="r">  (scalar)
		<@var="c">  (scalar)

Rearranges the elements of <@var="X"> into a matrix with <@var="r"> rows and <@var="c"> columns. Elements are read from <@var="X"> and written to the target in column-major order. If <@var="X"> contains fewer than <@itl="k"> = <@itl="rc"> elements, the elements are repeated cyclically; otherwise, if <@var="X"> has more elements, only the first <@itl="k"> are used. 

See also <@ref="cols">, <@ref="rows">, <@ref="unvech">, <@ref="vec">, <@ref="vech">. 

# msortby
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="j">  (scalar)

Returns a matrix in which the rows of <@var="X"> are reordered by increasing value of the elements in column <@var="j">. 

# muniform
Output: 	matrix 
Arguments:	<@var="r">  (scalar)
		<@var="c">  (scalar)

Returns a matrix with <@var="r"> rows and <@var="c"> columns, filled with uniform (0,1) pseudo-random variates. Note: the preferred method for generating a scalar uniform r.v. is recasting the output of <@lit="muniform"> to a scalar, as in 

<code>          
	  scalar x = muniform(1,1)
</code>

See also <@ref="mnormal">, <@ref="uniform">. 

# mwrite
Output: 	scalar 
Arguments:	<@var="X">  (matrix)
		<@var="s">  (string)

Writes the matrix <@var="X"> to a plain text file named <@var="s">. The file will contain on the first line two integers, separated by a tab character, with the number of rows and columns; on the next lines, the matrix elements in scientific notation, separated by tabs (one line per row). 

If file <@var="s"> already exists, it will be overwritten. The return value is 0 on successful completion; if an error occurs, such as the file being unwritable, the return value will be non-zero. 

Matrices stored via the <@lit="mwrite"> command can be easily read by other programs; see <@pdf="the Gretl User's Guide"> for details. 

See also <@ref="mread">. 

# mxtab
Output: 	matrix 
Arguments:	<@var="x">  (series or vector)
		<@var="y">  (series or vector)

Returns a matrix holding the cross tabulation of the values contained in <@var="x"> (by row) and <@var="y"> (by column). The two arguments should be of the same type (both series or both column vectors), and because of the typical usage of this function, are assumed to contain integer values only. 

See also <@ref="values">. 

# nelem
Output: 	scalar 
Argument: 	<@var="L">  (list)

Returns the number of items in list <@var="L">. 

# nobs
Output: 	scalar 
Argument: 	<@var="y">  (series)

Returns the number of non-missing observations for the variable <@var="y"> in the currently selected sample. 

# normal
Output: 	series 
Arguments:	<@var="μ">  (scalar)
		<@var="σ">  (scalar)

Generates a series of Gaussian pseudo-random variates with mean μ and standard deviation σ. If no arguments are supplied, standard normal variates <@itl="N">(0,1) are produced. 

See also <@ref="randgen">, <@ref="normal">, <@ref="genpois">, <@ref="mnormal">, <@ref="muniform">. 

# nullspace
Output: 	matrix 
Argument: 	<@var="A">  (matrix)

Computes the right nullspace of <@var="A">, via the singular value decomposition: the result is a matrix <@itl="B"> such that the product <@itl="AB"> is a zero matrix, except when <@var="A"> has full column rank, in which case an empty matrix is returned. Otherwise, if <@var="A"> is <@itl="m">×<@itl="n">, <@itl="B"> will be <@itl="n"> by (<@itl="n"> – <@itl="r">), where <@itl="r"> is the rank of <@var="A">. 

See also <@ref="rank">, <@ref="svd">. 

# obs
Output: 	series 

Returns a series of consecutive integers, setting 1 at the start of the dataset. Note that the result is invariant to subsampling. This function is especially useful with time-series datasets. Note: you can write <@lit="t"> instead of <@lit="obs"> with the same effect. 

See also <@ref="obsnum">. 

# obsnum
Output: 	scalar 
Argument: 	<@var="s">  (string)

Returns an integer corresponding to the observation specified by the string <@itl="s">. Note that the result is invariant to subsampling. This function is especially useful with time-series datasets. For example, the following code 

<code>          
	  open denmark 
	  k = obsnum(1980:1)
</code>

yields <@lit="k = 25">, indicating that the first quarter of 1980 is the 25th observation in the <@lit="denmark"> dataset. 

See also <@ref="obs">. 

# ok
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or list)

Returns a binary variable holding 1 if <@itl="x"> is not <@lit="NA">. If <@itl="x"> is a series, the comparison is done element by element. If <@itl="x"> is a list of series, the output is a series with 0 at the observations for which at least one series in the list is missing, and 1 otherwise. 

See also <@ref="missing">, <@ref="misszero">, <@ref="zeromiss">. 

# onenorm
Output: 	scalar 
Argument: 	<@var="X">  (matrix)

Returns the 1-norm of the matrix <@var="X">, that is, the maximum across the columns of <@var="X"> of the sum of absolute values of the column elements. 

See also <@ref="infnorm">, <@ref="rcond">. 

# ones
Output: 	matrix 
Arguments:	<@var="r">  (scalar)
		<@var="c">  (scalar)

Outputs a matrix with <@itl="r"> rows and <@itl="c"> columns, filled with ones. 

See also <@ref="seq">, <@ref="zeros">. 

# orthdev
Output: 	series 
Argument: 	<@var="y">  (series)

Only applicable if the currently open dataset has a panel structure. Computes the forward orthogonal deviations for variable <@var="y">. 

This transformation is sometimes used instead of differencing to remove individual effects from panel data. For compatibility with first differences, the deviations are stored one step ahead of their true temporal location (that is, the value at observation <@itl="t"> is the deviation that, strictly speaking, belongs at <@itl="t"> – 1). That way one loses the first observation in each time series, not the last. 

See also <@ref="diff">. 

# pdf
Output: 	same type as input 
Arguments:	<@var="c">  (character)
		<@var="…">  (see below)
		<@var="x">  (scalar, series or matrix)
Examples: 	<@lit="f1 = pdf(N, -2.5)">
		<@lit="f2 = pdf(X, 3, y)">
		<@lit="f3 = pdf(W, shape, scale, y)">

Probability density function calculator. Returns the density at <@var="x"> of the distribution identified by the code <@var="c">. See <@ref="cdf"> for details of the required arguments. The distributions supported by the <@lit="pdf"> function are the normal, Student's <@itl="t">, chi-square, <@itl="F">, Gamma and Weibull. 

For the normal distribution, see also <@ref="dnorm">. 

# pmax
Output: 	series 
Argument: 	<@var="y">  (series)

Only applicable if the currently open dataset has a panel structure. Returns the per-unit maximum for variable <@var="y">. 

Missing values are skipped. See also <@ref="pmin">, <@ref="pmean">, <@ref="pnobs">, <@ref="psd">. 

# pmean
Output: 	series 
Argument: 	<@var="y">  (series)

Only applicable if the currently open dataset has a panel structure. Computes the per-unit mean for variable <@var="y">; that is, the sum of the valid observations for each unit divided by the number of valid observations for each unit. 

Missing values are skipped. See also <@ref="pmax">, <@ref="pmin">, <@ref="pnobs">, <@ref="psd">. 

# pmin
Output: 	series 
Argument: 	<@var="y">  (series)

Only applicable if the currently open dataset has a panel structure. Returns the per-unit mimimum for variable <@var="y">. 

Missing values are skipped. See also <@ref="pmax">, <@ref="pmean">, <@ref="pnobs">, <@ref="psd">. 

# pnobs
Output: 	series 
Argument: 	<@var="y">  (series)

Only applicable if the currently open dataset has a panel structure. Returns for each unit the number of non-missing cases for the variable <@var="y">. 

Missing values are skipped. See also <@ref="pmax">, <@ref="pmin">, <@ref="pmean">, <@ref="psd">. 

# polroots
Output: 	matrix 
Argument: 	<@var="a">  (vector)

Finds the roots of a polynomial. If the polynomial is of degree <@itl="p">, the vector <@var="a"> should contain <@itl="p"> + 1 coefficients in ascending order, i.e. starting with the constant and ending with the coefficient on <@itl="x"><@sup="p">. 

If all the roots are real they are returned in a column vector of length <@itl="p">, otherwise a <@itl="p">×<@itl="2"> matrix is returned, the real parts in the first column and the imaginary parts in the second. 

# princomp
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="p">  (scalar)

Let the matrix <@var="X"> be <@itl="T">×<@itl="k">, containing <@itl="T"> observations on <@itl="k"> variables. The argument <@var="p"> must be a positive integer less than or equal to <@itl="k">. This function returns a <@itl="T">×<@itl="p"> matrix, <@itl="P">, holding the first <@itl="p"> principal components of <@var="X">. 

The elements of <@itl="P"> are computed as the sum from <@itl="i"> to <@itl="k"> of <@itl="Z"><@sub="ti"> times <@itl="v"><@sub="ji">, where <@itl="Z"><@sub="ti"> is the standardized value of variable <@itl="i"> at observation <@itl="t"> and <@itl="v"><@sub="ji"> is the <@itl="j">th eigenvector of the correlation matrix of the <@itl="X"><@sub="i">s, with the eigenvectors ordered by decreasing value of the corresponding eigenvalues. 

See also <@ref="eigensym">. 

# psd
Output: 	series 
Argument: 	<@var="y">  (series)

Only applicable if the currently open dataset has a panel structure. Computes the per-unit sample standard deviation for variable <@itl="y">. The denominator used is the sample size for each unit minus 1, unless the number of valid observations for the given unit is 1 (in which case 0 is returned) or 0 (in which case <@lit="NA"> is returned). 

Note: this function makes it possible to check whether a given variable (say, <@lit="X">) is time-invariant via the condition <@lit="max(psd(X)) = 0">. 

See also <@ref="pmax">, <@ref="pmin">, <@ref="pmean">, <@ref="pnobs">. 

# pvalue
Output: 	same type as input 
Arguments:	<@var="c">  (character)
		<@var="…">  (see below)
		<@var="x">  (scalar, series or matrix)
Examples: 	<@lit="p1 = pvalue(z, 2.2)">
		<@lit="p2 = pvalue(X, 3, 5.67)">
		<@lit="p2 = pvalue(F, 3, 30, 5.67)">

<@itl="P">-value calculator. Returns <@itl="P(X > x)">, where the distribution <@itl="X"> is determined by the character <@var="c">. Between the arguments <@var="c"> and <@var="x">, zero or more additional arguments are required to specify the parameters of the distribution; see <@ref="cdf"> for details. The distributions supported by the <@lit="pval"> function are the standard normal, <@itl="t">, Chi square, <@itl="F">, gamma, binomial, Poisson and Weibull. 

See also <@ref="critical">, <@ref="invcdf">. 

# qform
Output: 	matrix 
Arguments:	<@var="x">  (matrix)
		<@var="A">  (symmetric matrix)

Computes the quadratic form <@itl="Y = xAx'">. Using this function instead of ordinary matrix multiplication guarantees more speed and better accuracy. If <@var="x"> and <@var="A"> are not conformable, or <@var="A"> is not symmetric, an error is returned. 

# qnorm
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns quantiles for the standard normal distribution. If <@var="x"> is not between 0 and 1, <@lit="NA"> is returned. See also <@ref="cnorm">, <@ref="dnorm">. 

# qrdecomp
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="&R">  (reference to matrix, or <@lit="null">)

Computes the QR decomposition of an <@itl="m">×<@itl="n"> matrix <@var="X">, that is <@itl="X = QR"> where <@itl="Q"> is an <@itl="m">×<@itl="n"> orthogonal matrix and <@itl="R"> is an <@itl="n">×<@itl="n"> upper triangular matrix. The matrix <@itl="Q"> is returned directly, while <@itl="R"> can be retrieved via the optional second argument. 

See also <@ref="eigengen">, <@ref="eigensym">, <@ref="svd">. 

# quantile
Output: 	scalar or row vector 
Arguments:	<@var="y">  (series or matrix)
		<@var="p">  (scalar between 0 and 1)

Given a series argument, returns the <@var="p">-quantile for the series. For example, when <@itl="p"> = 0.5, the median is returned. Given a matrix argument, returns a row vector containing the <@var="p">-quantiles for the columns of <@var="y">; that is, each column is treated as a series. 

# rank
Output: 	scalar 
Argument: 	<@var="X">  (matrix)

Returns the rank of <@var="X">, numerically computed via the singular value decomposition. See also <@ref="svd">. 

# ranking
Output: 	series 
Argument: 	<@var="y">  (series)

Returns a series with the ranks of <@itl="y">. The rank for observation <@itl="i"> is the number of elements in the series that are less than <@itl="y"><@sub="i"> plus one half the number of elements in the series that are equal to <@itl="y"><@sub="i">. (Intuitively, you may think of chess points, where victory gives you one point and a draw gives you half a point.) One is added so the lowest rank is 1 instead of 0. 

See also <@ref="sort">, <@ref="sortby">. 

# randgen
Output: 	series 
Arguments:	<@var="c">  (character)
		<@var="a">  (scalar)
		<@var="b">  (scalar)
Examples: 	<@lit="series x = randgen(u, 0, 100)">
		<@lit="series t14 = randgen(t, 14)">
		<@lit="series y = randgen(B, 0.6, 30)">
		<@lit="series g = randgen(G, 1, 1)">

All-purpose random number generator. The parameter <@var="c"> is a character, which specifies from which distribution the pseudo-random numbers should be drawn; <@var="a"> and, in some cases, <@var="b"> gauge the shape of the distribution. 

<indent>
• Uniform (continuous) (c = u or U): minimum; maximum 
</indent>

<indent>
• Standard normal (c = z, n, or N): mean; standard deviation 
</indent>

<indent>
• Student's t (t): degrees of freedom 
</indent>

<indent>
• Chi square (c, x, or X): degrees of freedom 
</indent>

<indent>
• Snedecor's F (f or F): df (num.); df (den.) 
</indent>

<indent>
• Gamma (g or G): shape; scale 
</indent>

<indent>
• Binomial (b or B): probability; number of trials 
</indent>

<indent>
• Poisson (p or P): Mean 
</indent>

<indent>
• Weibull (w or W): shape; scale 
</indent>

See also <@ref="normal">, <@ref="uniform">, <@ref="genpois">. 

# rcond
Output: 	scalar 
Argument: 	<@var="A">  (square matrix)

Returns the reciprocal condition number for <@var="A"> with respect to the 1-norm. In many circumstances, this is a better measure of the sensitivity of <@var="A"> to numerical operations such as inversion than the determinant. 

The value is computed as the reciprocal of the product, 1-norm of <@var="A"> times 1-norm of <@var="A">-inverse. 

See also <@ref="det">, <@ref="ldet">, <@ref="onenorm">. 

# readfile
Output: 	string 
Argument: 	<@var="fname">  (string)

If a file by the name of <@var="fname"> exists and is readable, returns a string containing the content of this file, otherwise flags an error. 

Also see the <@xrf="sscanf"> command. 

# resample
Output: 	same type as input 
Argument: 	<@var="x">  (series or matrix)

Resamples from <@var="x"> with replacement. In the case of a series argument, each value of the returned series, <@itl="y"><@sub="t">, is drawn from among all the values of <@itl="x"><@sub="t"> with equal probability. When a matrix argument is given, each row of the returned matrix is drawn from the rows of <@var="x"> with equal probability. 

# round
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Rounds to the nearest integer. Note that when <@itl="x"> lies halfway between two integers, rounding is done "away from zero", so for example 2.5 rounds to 3, but <@lit="round(-3.5)"> gives –4. This is a common convention in spreadsheet programs, but other software may yield different results. See also <@ref="ceil">, <@ref="floor">, <@ref="int">. 

# rows
Output: 	scalar 
Argument: 	<@var="X">  (matrix)

Number of rows of the matrix <@var="X">. See also <@ref="cols">, <@ref="mshape">, <@ref="unvech">, <@ref="vec">, <@ref="vech">. 

# sd
Output: 	scalar or series 
Argument: 	<@var="x">  (series or list)

If <@var="x"> is a series, returns the (scalar) sample standard deviation, skipping any missing observations. 

If <@var="x"> is a list, returns a series <@itl="y"> such that <@itl="y"><@sub="t"> is the sample standard deviation of the values of the variables in the list at observation <@itl="t">, or <@lit="NA"> if there are any missing values at <@itl="t">. 

See also <@ref="var">. 

# sdc
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the standard deviations of the columns of <@var="X"> (with no degrees of freedom correction). See also <@ref="meanc">, <@ref="sumc">. 

# sdiff
Output: 	same type as input 
Argument: 	<@var="y">  (series or list)

Computes seasonal differences: <@itl="y(t) - y(t-k)">, where <@itl="k"> is the periodicity of the current dataset (see <@ref="$pd">). Starting values are set to <@lit="NA">. 

When a list is returned, the individual variables are automatically named according to the template <@lit="sd_"><@var="varname"> where <@var="varname"> is the name of the original series. The name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

See also <@ref="diff">, <@ref="ldiff">. 

# selifc
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="b">  (row vector)

Selects from <@var="A"> only the columns for which the corresponding element of <@var="b"> is non-zero. <@var="b"> must be a row vector with the same number of columns as <@var="A">. 

See also <@ref="selifr">. 

# selifr
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="b">  (column vector)

Selects from <@var="A"> only the rows for which the corresponding element of <@var="b"> is non-zero. <@var="b"> must be a column vector with the same number of rows as <@var="A">. 

See also <@ref="selifc">, <@ref="trimr">. 

# seq
Output: 	row vector 
Arguments:	<@var="a">  (scalar)
		<@var="b">  (scalar)

Returns a row vector filled with consecutive integers, with <@var="a"> as first element and <@var="b"> last. If <@var="a"> is greater than <@var="b"> the sequence will be decreasing. If either argument is not integral its fractional part is discarded. 

See also <@ref="ones">, <@ref="zeros">. 

# sin
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Sine. See also <@ref="cos">, <@ref="tan">, <@ref="atan">. 

# sort
Output: 	same type as input 
Argument: 	<@var="x">  (series or vector)

Sorts <@var="x"> in ascending order, skipping observations with missing values when <@itl="x"> is a series. See also <@ref="dsort">, <@ref="values">. For matrices specifically, see <@ref="msortby">. 

# sortby
Output: 	series 
Arguments:	<@var="y1">  (series)
		<@var="y2">  (series)

Returns a series containing the elements of <@var="y2"> sorted by increasing value of the first argument, <@var="y1">. See also <@ref="sort">, <@ref="ranking">. 

# sqrt
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Square root of <@var="x">; produces <@lit="NA"> for negative values. 

# sst
Output: 	scalar 
Argument: 	<@var="y">  (series)

Sum of squared deviations from the mean for the non-missing observations in series <@var="y">. See also <@ref="var">. 

# strlen
Output: 	scalar 
Argument: 	<@var="s">  (string)

Returns the number of characters in <@var="s">. 

# strstr
Output: 	string 
Arguments:	<@var="s1">  (string)
		<@var="s2">  (string)

Searches <@var="s1"> for an occurrence of the string <@var="s2">. If a match is found, returns a copy of the portion of <@var="s1"> that starts with <@var="s2">, otherwise returns an empty string. 

# sum
Output: 	scalar 
Argument: 	<@var="y">  (series)

Sum of the non-missing observations in series <@var="y">. 

# sumc
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the sums of the columns of <@var="X">. See also <@ref="meanc">, <@ref="sumr">. 

# sumr
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the sums of the rows of <@var="X">. See also <@ref="meanr">, <@ref="sumc">. 

# svd
Output: 	row vector 
Arguments:	<@var="X">  (matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)
		<@var="&V">  (reference to matrix, or <@lit="null">)

Performs the singular values decomposition of the matrix <@var="X">. 

The singular values are returned in a row vector. The left and/or right singular vectors <@itl="U"> and <@itl="V"> may be obtained by supplying non-null values for arguments 2 and 3, respectively. For any matrix <@lit="A">, the code 

<code>          
	  s = svd(A, &U, &V) 
	  B = (U .* s) * V
</code>

should yield <@lit="B"> identical to <@lit="A"> (apart from machine precision). 

See also <@ref="eigengen">, <@ref="eigensym">, <@ref="qrdecomp">. 

# tan
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Tangent. 

# tr
Output: 	scalar 
Argument: 	<@var="A">  (square matrix)

Returns the trace of the square matrix <@var="A">, namely <@itl="the sum of its diagonal elements">. See also <@ref="diag">. 

# transp
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Matrix transposition. Note: this is rarely used; in order to get the transpose of a matrix, in most cases you can just use the prime operator: <@lit="X'">. 

# trimr
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="ttop">  (scalar)
		<@var="tbot">  (scalar)

Returns a matrix that is a copy of <@var="X"> with <@var="ttop"> rows trimmed at the top and <@var="tbot"> rows trimmed at the bottom. The latter two arguments must be non-negative, and must sum to less than the total rows of <@var="X">. 

See also <@ref="selifr">. 

# uniform
Output: 	series 
Arguments:	<@var="a">  (scalar)
		<@var="b">  (scalar)

Generates a series of uniform pseudo-random variates in the interval (<@var="a">, <@var="b">), or, if no arguments are supplied, in the interval (0,1). The algorithm used is the Mersenne Twister by Matsumoto and Nishimura (1998). 

See also <@ref="randgen">, <@ref="normal">, <@ref="genpois">, <@ref="mnormal">, <@ref="muniform">. 

# unvech
Output: 	square matrix 
Arguments:	<@var="v">  (vector)
		<@var="b">  (scalar)

Returns an <@itl="n">×<@itl="n"> symmetric matrix obtained by rearranging the elements of <@itl="v">. The number of elements in <@itl="v"> must be a triangular integer — i.e., a number <@itl="k"> such that an integer <@itl="n"> exists with the property <@itl="k = n(n+1)/2">. This is the inverse of the function <@ref="vech">. 

See also <@ref="mshape">. 

# upper
Output: 	square matrix 
Argument: 	<@var="A">  (square matrix)

Returns an <@itl="n">×<@itl="n"> upper triangular matrix: the elements on and above the diagonal are equal to the corresponding elements of <@var="A">; the remaining elements are zero. 

See also <@ref="lower">. 

# values
Output: 	column vector 
Argument: 	<@var="x">  (series or vector)

Returns a vector containing the distinct elements of <@var="x"> sorted in ascending order. If you wish to truncate the values to integers before applying this function, use the expression <@lit="values(int(x))">. 

See also <@ref="dsort">, <@ref="sort">. 

# var
Output: 	scalar or series 
Argument: 	<@var="x">  (series or list)

If <@var="x"> is a series, returns the (scalar) sample variance, skipping any missing observations. 

If <@var="x"> is a list, returns a series <@itl="y"> such that <@itl="y"><@sub="t"> is the sample variance of the values of the variables in the list at observation <@itl="t">, or <@lit="NA"> if there are any missing values at <@itl="t">. 

In each case the sum of squared deviations from the mean is divided by (<@itl="n"> – 1) for <@itl="n"> > 1. Otherwise the variance is given as zero if <@itl="n"> = 1, or as <@lit="NA"> if <@itl="n"> = 0. 

See also <@ref="sd">. 

# varname
Output: 	string 
Argument: 	<@var="i">  (scalar)

Returns the name of the variable with ID number <@var="i">, or generates an error if there is no such variable. 

# varnum
Output: 	scalar 
Argument: 	<@var="varname">  (string)

Returns the ID number of the variable called <@var="varname">, or NA is there is no such variable. 

# vec
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Stacks the columns of <@var="X"> as a column vector. See also <@ref="mshape">, <@ref="unvech">, <@ref="vech">. 

# vech
Output: 	column vector 
Argument: 	<@var="A">  (square matrix)

Returns in a column vector the elements of <@var="A"> on and above the diagonal. Typically, this function is used on symmetric matrices; in this case, it can be undone by the function <@ref="unvech">. See also <@ref="vec">. 

# wmean
Output: 	series 
Arguments:	<@var="Y">  (list)
		<@var="W">  (list)

Returns a series <@itl="y"> such that <@itl="y"><@sub="t"> is the weighted mean of the values of the variables in list <@var="Y"> at observation <@itl="t">, the respective weights given by the values of the variables in list <@var="W"> at <@itl="t">. The weights can therefore be time-varying. The lists <@var="Y"> and <@var="W"> must be of the same length and the weights must be non-negative. 

See also <@ref="wsd">, <@ref="wvar">. 

# wsd
Output: 	series 
Arguments:	<@var="Y">  (list)
		<@var="W">  (list)

Returns a series <@itl="y"> such that <@itl="y"><@sub="t"> is the weighted sample standard deviation of the values of the variables in list <@var="Y"> at observation <@itl="t">, the respective weights given by the values of the variables in list <@var="W"> at <@itl="t">. The weights can therefore be time-varying. The lists <@var="Y"> and <@var="W"> must be of the same length and the weights must be non-negative. 

See also <@ref="wmean">, <@ref="wvar">. 

# wvar
Output: 	series 
Arguments:	<@var="X">  (list)
		<@var="W">  (list)

Returns a series <@itl="y"> such that <@itl="y"><@sub="t"> is the weighted sample variance of the values of the variables in list <@var="X"> at observation <@itl="t">, the respective weights given by the values of the variables in list <@var="W"> at <@itl="t">. The weights can therefore be time-varying. The lists <@var="Y"> and <@var="W"> must be of the same length and the weights must be non-negative. 

See also <@ref="wmean">, <@ref="wsd">. 

# xpx
Output: 	list 
Argument: 	<@var="L">  (list)

Returns a list that references the squares and cross-products of the variables in list <@var="L">. Squares are named on the pattern <@lit="sq_"><@var="varname"> and cross-products on the pattern <@var="var1"><@lit="_"><@var="var2">. The input variable names are truncated if need be, and the output names may be adjusted in case of duplication of names in the returned list. 

# zeromiss
Output: 	same type as input 
Argument: 	<@var="x">  (scalar or series)

Converts zeros to <@lit="NA">s. If <@var="x"> is a series, the conversion is done element by element. See also <@ref="missing">, <@ref="misszero">, <@ref="ok">. 

# zeros
Output: 	matrix 
Arguments:	<@var="r">  (scalar)
		<@var="c">  (scalar)

Outputs a zero matrix with <@itl="r"> rows and <@itl="c"> columns. See also <@ref="ones">, <@ref="seq">. 

