\section{Acessores}
\label{sec:accessors}

\subsection{\$ahat}
\hypertarget{func-dolahat}{}

\begin{tabular}{ll}
Output:     & series\\
\end{tabular}

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

\subsection{\$aic}
\hypertarget{func-dolaic}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Returns the Akaike Information Criterion for the last estimated
	  model. 

\subsection{\$bic}
\hypertarget{func-dolbic}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

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

\subsection{\$coeff}
\hypertarget{func-dolcoeff}{}

\begin{tabular}{ll}
Output:     & scalar or matrix\\
Argument:   & \textsl{s} (name of coefficient, optional)\\
\end{tabular}

	The \verb@$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
	  \textsl{s}.
	  See also \hyperlink{func-dolstderr}{\$stderr}, \hyperlink{func-dolvcv}{\$vcv}.

	  Example:

\begin{code}
	  open bjg
	  arima 0 1 1 ; 0 1 1 ; lg 
	  b = $coeff 
	  macoef = $coeff(theta_1)

\end{code}

	  If the ``model'' in question is actually a system (a
	  VAR or VECM, or system of simultaneous equations),
	  \verb@$coeff@ with no parameters returns the matrix of
	  coefficients, one column per equation.

\subsection{\$compan}
\hypertarget{func-dolcompan}{}

\begin{tabular}{ll}
Output:     & matrix\\
\end{tabular}

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

\subsection{\$datatype}
\hypertarget{func-doldatatype}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  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.

\subsection{\$df}
\hypertarget{func-doldf}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Returns the degrees of freedom of the last estimated model.

\subsection{\$ess}
\hypertarget{func-doless}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

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

\subsection{\$gmmcrit}
\hypertarget{func-dolgmmcrit}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Must follow a \texttt{gmm} block. Returns the value of the
	  objective function at its minimum.

\subsection{\$h}
\hypertarget{func-dolh}{}

\begin{tabular}{ll}
Output:     & series\\
\end{tabular}

	  Must follow a \texttt{garch} command. Returns the estimated
	  conditional variance.

\subsection{\$hausman}
\hypertarget{func-dolhausman}{}

\begin{tabular}{ll}
Output:     & row vector\\
\end{tabular}

	  Must follow a \texttt{tsls} command. Returns a \ensuremath{1\times 3} vector, containing the value of the Hausman test
	  statistic, the corresponding degrees of freedom and p-value,
	  in this order.

\subsection{\$hqc}
\hypertarget{func-dolhqc}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

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

\subsection{\$jalpha}
\hypertarget{func-doljalpha}{}

\begin{tabular}{ll}
Output:     & matrix\\
\end{tabular}

	  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.

\subsection{\$jbeta}
\hypertarget{func-doljbeta}{}

\begin{tabular}{ll}
Output:     & matrix\\
\end{tabular}

	  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.

\subsection{\$jvbeta}
\hypertarget{func-doljvbeta}{}

\begin{tabular}{ll}
Output:     & square matrix\\
\end{tabular}

	  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 \texttt{restrict} command with the
	  \verb@--full@ option, a singular matrix with \ensuremath{(n+m)r}
	  rows will be returned (\ensuremath{n} being the number of
	  endogenous variables, \ensuremath{m} the number of exogenous
          variables that are restricted to the cointegration space,
          and \ensuremath{r} the cointegration rank).

	  Example: the code

\begin{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

\end{code}

	  produces the following output.

\begin{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 

\end{code}

\subsection{\$lnl}
\hypertarget{func-dollnl}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

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

\subsection{\$ncoeff}
\hypertarget{func-dolncoeff}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Total number of coefficients estimated in the last model.

\subsection{\$nobs}
\hypertarget{func-dnobs}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Returns the number of observations in the currently selected
	  sample.

\subsection{\$nvars}
\hypertarget{func-dolnvars}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

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

\subsection{\$pd}
\hypertarget{func-dolpd}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

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

\subsection{\$pvalue}
\hypertarget{func-dpvalue}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Returns the p-value of the test statistic that was generated by
	  the last explicit hypothesis-testing command, if any (e.g.
	  \texttt{chow}).  See \GUG{} 
	  for details.
	  See also \hyperlink{func-doltest}{\$test}.

\subsection{\$rho}
\hypertarget{func-dolrho}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{n} (scalar, optional)\\
\end{tabular}

	  Without arguments, returns the first-order autoregressive
	  coefficient for the residuals of the last model. After
	  estimating a model via the \texttt{ar} command, the syntax
	  \verb@$rho(n)@ returns the corresponding estimate of
	  $\rho$(\ensuremath{n}).

\subsection{\$rsq}
\hypertarget{func-dolrsq}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Returns the unadjusted \ensuremath{R}\ensuremath{^{2}} from the
	  last estimated model.

\subsection{\$sample}
\hypertarget{func-dolsample}{}

\begin{tabular}{ll}
Output:     & series\\
\end{tabular}

	  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: 

\begin{code}
	  ols y 0 xlist
	  genr sdum = $sample
	  smpl sdum --dummy

\end{code}

\subsection{\$sargan}
\hypertarget{func-dolsargan}{}

\begin{tabular}{ll}
Output:     & row vector\\
\end{tabular}

	  Must follow a \texttt{tsls} command. Returns a \ensuremath{1\times 3} vector, containing the value of the Sargan
	  over-identification test statistic, the corresponding
	  degrees of freedom and p-value, in this order.

\subsection{\$sigma}
\hypertarget{func-dolsigma}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

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

\subsection{\$stderr}
\hypertarget{func-dolstderr}{}

\begin{tabular}{ll}
Output:     & scalar or matrix\\
Argument:   & \textsl{s} (name of coefficient, optional)\\
\end{tabular}

	  The \verb@$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
	  \textsl{s}.  
	  See also \hyperlink{func-dolcoeff}{\$coeff}, \hyperlink{func-dolvcv}{\$vcv}.

\subsection{\$stopwatch}
\hypertarget{func-dolstopwatch}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Must be preceded by \texttt{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 \texttt{set	    stopwatch} command.  At each access the clock is reset, so
	  subsequent uses of \verb@$stopwatch@ yield the seconds of CPU
	  time since the previous access.

\subsection{\$T}
\hypertarget{func-dolT}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Number of observations used in estimating the last model.

\subsection{\$t1}
\hypertarget{func-dolt1}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

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

\subsection{\$t2}
\hypertarget{func-dolt2}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

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

\subsection{\$test}
\hypertarget{func-doltest}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Returns the value of the test statistic that was generated by
	  the last explicit hypothesis-testing command, if any (e.g.{}
	  \texttt{chow}). See \GUG{} 
	  for details.
	  See also \hyperlink{func-dpvalue}{\$pvalue}.

\subsection{\$trsq}
\hypertarget{func-doltrsq}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Returns \ensuremath{TR}\ensuremath{^{2}} (sample size times
	  R-squared) from the last model.

\subsection{\$uhat}
\hypertarget{func-doluhat}{}

\begin{tabular}{ll}
Output:     & series\\
\end{tabular}

	  Returns the residuals from the last model. This may have
	  different meanings for different estimators. For example, after
	  an ARMA estimation \verb@$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),
	  \verb@$uhat@ with no parameters retrieves the matrix of
	  residuals, one column per equation.

\subsection{\$unit}
\hypertarget{func-dolunit}{}

\begin{tabular}{ll}
Output:     & series\\
\end{tabular}

	  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.

\subsection{\$vcv}
\hypertarget{func-dolvcv}{}

\begin{tabular}{ll}
Output:     & scalar or matrix\\
Arguments:  & \textsl{s1} (name of coefficient, optional)\\
           & \textsl{s2} (name of coefficient, optional)\\
\end{tabular}

	  The \verb@$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
	  \textsl{s1} and \textsl{s2}.  
	  See also \hyperlink{func-dolcoeff}{\$coeff}, \hyperlink{func-dolstderr}{\$stderr}.

	  If the ``model'' in question is actually a system (a
	  VAR or VECM, or system of simultaneous equations),
	  \verb@$vcv@ with no parameters returns the cross-equation
	  covariance matrix.

\subsection{\$version}
\hypertarget{func-dolversion}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  Returns an integer value that codes for the program version. The
	  gretl version string takes the form \texttt{x.y.z} (for example,
	  1.7.6).  The return value from this accessor is formed as
	  \texttt{10000*x + 100*y + z}, so that 1.7.6 translates as 10706.

\subsection{\$windows}
\hypertarget{func-dolwindows}{}

\begin{tabular}{ll}
Output:     & scalar\\
\end{tabular}

	  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 \hyperlink{cmd-shell}{shell} command.

\subsection{\$xlist}
\hypertarget{func-dolxlist}{}

\begin{tabular}{ll}
Output:     & list\\
\end{tabular}

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

\subsection{\$yhat}
\hypertarget{func-dolyhat}{}

\begin{tabular}{ll}
Output:     & series\\
\end{tabular}

	  Returns the fitted values from the last regression.

\section{Funcoes}
\label{sec:functions}

\subsection{abs}
\hypertarget{func-abs}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Absolute value.

\subsection{acos}
\hypertarget{func-acos}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  The arc cosine of \textsl{x}, that is, the value whose
	  cosine is \textsl{x}.  The result is in radians; the input
	  should be in the range $-$1 to 1.

\subsection{asin}
\hypertarget{func-asin}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  The arc sine of \textsl{x}, that is, the value whose sine
	  is \textsl{x}.  The result is in radians; the input should
	  be in the range $-$1 to 1.

\subsection{atan}
\hypertarget{func-atan}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  The arc tangent of \textsl{x}, that is, the value whose
	  tangent is \textsl{x}.  The result is in radians.

\subsection{BFGSmax}
\hypertarget{func-BFGSmax}{}

\begin{tabular}{ll}
Output:     & scalar\\
Arguments:  & \textsl{b} (vector)\\
           & \textsl{s} (string)\\
\end{tabular}

	  Numerical maximization via the method of Broyden, Fletcher, Goldfarb
	  and Shanno.  The vector \textsl{b} should hold the initial
	  values of a set of parameters, and the string \textsl{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, \texttt{BFGSmax} returns the maximized value of the
	  criterion, and \textsl{b} holds the parameter values which
	  produce the maximum.  

	  For more details and examples see the chapter
	  on special functions in \texttt{genr} in 
	  \GUG{}.
	  See also \hyperlink{func-fdjac}{fdjac}.

\subsection{bkfilt}
\hypertarget{func-bkfilt}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Extracts the cyclical component of series \textsl{y}
	  via the Baxter--King bandpass filter, a two-sided symmetric
	  filter. See \GUG{} for details.
	  See also \hyperlink{func-hpfilt}{hpfilt}.

\subsection{cdemean}
\hypertarget{func-cdemean}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Centers the columns of matrix \textsl{X} around their
	  means.

\subsection{cdf}
\hypertarget{func-cdf}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Arguments:  & \textsl{c} (character)\\
           & \textsl{\dots{}} (see below)\\
           & \textsl{x} (scalar, series or matrix)\\
Examples:    & \texttt{p1 = cdf(N, -2.5)} \\ 
 & \texttt{p2 = cdf(X, 3, 5.67)} \\ 
 & \texttt{p3 = cdf(D, 0.25, -1, 1)}
\end{tabular}

	  Cumulative distribution function calculator. Returns 
	  $P(X \le x)$, where the distribution \ensuremath{X} is
	  determined by the character \textsl{c}. Between the
	  arguments \textsl{c} and \textsl{x}, zero or
	  more additional arguments are required to specify the parameters
	  of the distribution, as follows.

	  \begin{center} 
	  \begin{tabular}{llll} 
	  \textit{Distribution} & \textsl{c} &
	  \textit{Arg} 2 & \textit{Arg} 3 \\[4pt] 
	  Standard normal & \texttt{z}, \texttt{n} or \texttt{N} & 
	  -- & -- \\ 
	  Bivariate normal & \texttt{D} & 
	  $\rho$ & -- \\ 
	  Student's $t$ (central) & \texttt{t} &  
	  degrees of freedom & -- \\ 
	  Chi square & \texttt{c}, \texttt{x} or \texttt{X} & 
	  degrees of freedom & -- \\ 
	  Snedecor's $F$ & \texttt{f} or \texttt{F} &
	  df (num.) & df (den.) \\ 
	  Gamma & \texttt{g} or \texttt{G} &
	  shape & scale \\ 
	  Binomial & \texttt{b} or \texttt{B} &
	  probability & trials \\ 
	  Poisson & \texttt{p} or \texttt{P} & 
	  mean & -- \\
	  Weibull & \texttt{w} or \texttt{W} & 
	  shape & scale
	  \end{tabular}
	  \end{center}

	  Note that most cases have aliases to help memorizing the codes.
	  The bivariate normal case is special: the syntax is \texttt{x =	    cdf(D, rho, z1, z2)} where \texttt{rho} is the
	  correlation between the variables \texttt{z1} and
	  \texttt{z2}.

	  The parametrization \app{gretl} uses for the Gamma random variate
	  implies that its density function can be written as
	  \[
	  f(x; k, \theta) = \frac{x^{k-1}}{\theta^k} \frac{e^{-x/\theta}}{\Gamma(k)}
	  \]
	  where $k>0$ is the shape parameter and $\theta>0$ is the scale
	  parameter.

	  See also \hyperlink{func-pdf}{pdf}, \hyperlink{func-critical}{critical}, \hyperlink{func-invcdf}{invcdf}, \hyperlink{func-pvalue}{pvalue}.

\subsection{cdiv}
\hypertarget{func-cdiv}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{Y} (matrix)\\
\end{tabular}

	  Complex division. The two arguments must have the same number of
	  rows, \ensuremath{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 \ensuremath{n\times 2}
	  matrix or, if the result has no imaginary part, an
	  \ensuremath{n}-vector.
	  See also \hyperlink{func-cmult}{cmult}.

\subsection{ceil}
\hypertarget{func-ceil}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Ceiling function: returns the smallest integer greater than or
	  equal to \textsl{x}. 
	  See also \hyperlink{func-floor}{floor}, \hyperlink{func-int}{int}.

\subsection{cholesky}
\hypertarget{func-cholesky}{}

\begin{tabular}{ll}
Output:     & square matrix\\
Argument:   & \textsl{A} (square matrix)\\
\end{tabular}

	  Peforms a Cholesky decomposition of the matrix
	  \textsl{A}, which is assumed to be symmetric and
	  positive definite. The result is a lower-triangular matrix
	  \ensuremath{K} which satisfies $A = KK'$. The function will fail if
	  \textsl{A} is not symmetric or not positive definite.

\subsection{cmult}
\hypertarget{func-cmult}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{Y} (matrix)\\
\end{tabular}

	  Complex multiplication. The two arguments must have the same
	  number of rows, \ensuremath{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
	  \ensuremath{n\times 2} matrix, or, if the result has no imaginary
	  part, an \ensuremath{n}-vector. 
	  See also \hyperlink{func-cdiv}{cdiv}.

\subsection{cnorm}
\hypertarget{func-cnorm}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Returns the cumulative distribution function for a standard
	  normal. 
	  See also \hyperlink{func-dnorm}{dnorm}, \hyperlink{func-qnorm}{qnorm}.

\subsection{colnames}
\hypertarget{func-colnames}{}

\begin{tabular}{ll}
Output:     & scalar\\
Arguments:  & \textsl{M} (matrix)\\
           & \textsl{s} (named list or string)\\
\end{tabular}

	  Attaches names to the columns of the \ensuremath{T\times k} matrix
	  \textsl{M}. If \textsl{s} is a named list, the
	  column names are copied from the names of the variables; the list
	  must have \ensuremath{k} members. If \textsl{s} is a
	  string, it should contain \ensuremath{k} space-separated
	  sub-strings.  The return value is 0 on successful completion,
	  non-zero on error.

\subsection{cols}
\hypertarget{func-cols}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  The number of columns of \textsl{X}. 
	  See also \hyperlink{func-mshape}{mshape}, \hyperlink{func-rows}{rows}, \hyperlink{func-unvech}{unvech}, \hyperlink{func-vec}{vec}, \hyperlink{func-vech}{vech}.

\subsection{corr}
\hypertarget{func-corr}{}

\begin{tabular}{ll}
Output:     & scalar\\
Arguments:  & \textsl{y1} (series)\\
           & \textsl{y2} (series)\\
\end{tabular}

	  Computes the correlation coefficient between \textsl{y1}
	  and \textsl{y2}. 
	  See also \hyperlink{func-cov}{cov}, \hyperlink{func-mcov}{mcov}, \hyperlink{func-mcorr}{mcorr}.

\subsection{cos}
\hypertarget{func-cos}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Cosine.

\subsection{cov}
\hypertarget{func-cov}{}

\begin{tabular}{ll}
Output:     & scalar\\
Arguments:  & \textsl{y1} (series)\\
           & \textsl{y2} (series)\\
\end{tabular}

	  Computes the covariance between \textsl{y1} and
	  \textsl{y2}. 
	  See also \hyperlink{func-corr}{corr}, \hyperlink{func-mcov}{mcov}, \hyperlink{func-mcorr}{mcorr}.

\subsection{critical}
\hypertarget{func-critical}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Arguments:  & \textsl{c} (character)\\
           & \textsl{\dots{}} (see below)\\
           & \textsl{p} (scalar, series or matrix)\\
Examples:    & \texttt{c1 = critical(t, 20, 0.025)} \\ 
 & \texttt{c2 = critical(F, 4, 48, 0.05)}
\end{tabular}

	  Critical value calculator. Returns \ensuremath{x} such that
	  $P(X > x) = p$, where the distribution \ensuremath{X}
	  is determined by the character \textsl{c}. Between the
	  arguments \textsl{c} and \textsl{p}, zero or
	  more additional arguments are required to specify the parameters
	  of the distribution, as follows.

	  \begin{center} 
	  \begin{tabular}{llll} 
	  \textit{Distribution} & \textsl{c} &
	  \textit{Arg} 2 & \textit{Arg} 3 \\[4pt]
	  Standard normal & \texttt{z}, \texttt{n} or \texttt{N} &
	  -- & -- \\ 
	  Student's $t$ (central) & \texttt{t} & 
	  degrees of freedom & -- \\ 
	  Chi square & \texttt{c}, \texttt{x} or \texttt{X} & 
	  degrees of freedom & -- \\
	  Snedecor's $F$ & \texttt{f} or \texttt{F} & 
	  df (num.) & df (den.) \\ 
	  Binomial & \texttt{b} or \texttt{B} & 
	  $p$ & $n$ \\ 
	  \end{tabular}
	  \end{center}

	  See also \hyperlink{func-cdf}{cdf}, \hyperlink{func-invcdf}{invcdf}, \hyperlink{func-pvalue}{pvalue}.

\subsection{cum}
\hypertarget{func-cum}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (series or matrix)\\
\end{tabular}

	  Cumulates \textsl{x}. When \ensuremath{x} is a series,
	  produces a series $y_t = \sum_{s=m}^t x_s$; the starting point of
	  the summation, \ensuremath{m}, is the first non-missing observation
	  of the currently selected sample.  If any missing values are
	  encountered in \ensuremath{x}, subsequent values of \ensuremath{y}
	  will be set to missing. When \textsl{x} is a matrix, its
	  elements are cumulated by columns.

	  See also \hyperlink{func-diff}{diff}.

\subsection{det}
\hypertarget{func-det}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{A} (square matrix)\\
\end{tabular}

	  Returns the determinant of \textsl{A}, computed via the
	  LU factorization.
	  See also \hyperlink{func-ldet}{ldet}, \hyperlink{func-rcond}{rcond}.

\subsection{diag}
\hypertarget{func-diag}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the principal diagonal of \textsl{X} in a
	  column vector. Note: if \textsl{X} is an
	  \ensuremath{m\times n} marix, the number of elements
	  of the output vector is min(\ensuremath{m}, \ensuremath{n}).
	  See also \hyperlink{func-tr}{tr}.

\subsection{diff}
\hypertarget{func-diff}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{y} (series, matrix or list)\\
\end{tabular}

	  Computes first differences.  If \textsl{y} is a series, or
	  a list of series, starting values are set to \texttt{NA}.  If
	  \textsl{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
	  \verb@d_@\textsl{varname} where \textsl{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 \hyperlink{func-cum}{cum}, \hyperlink{func-ldiff}{ldiff}, \hyperlink{func-sdiff}{sdiff}.

\subsection{dnorm}
\hypertarget{func-dnorm}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Returns the density of the standard normal distribution at
	  \textsl{x}.  To get the density for a non-standard
	  normal distribution at \ensuremath{x}, pass the
	  \ensuremath{z}-score of \ensuremath{x} to the \texttt{dnorm}
	  function and multiply the result by the Jacobian of the
	  \ensuremath{z} transformation, namely 1 over $\sigma$, as
	  illustrated below:

\begin{code}
	  mu = 100
	  sigma = 5
	  x = 109
	  fx = (1/sigma) * dnorm((x-mu)/sigma)

\end{code}

	  See also \hyperlink{func-cnorm}{cnorm}, \hyperlink{func-qnorm}{qnorm}.

\subsection{dsort}
\hypertarget{func-dsort}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (series or vector)\\
\end{tabular}

	  Sorts \textsl{x} in descending order, skipping
	  observations with missing values when \textsl{x} is a
	  series. 
	  See also \hyperlink{func-sort}{sort}, \hyperlink{func-values}{values}.

\subsection{dummify}
\hypertarget{func-dummify}{}

\begin{tabular}{ll}
Output:     & list\\
Argument:   & \textsl{x} (series or list)\\
\end{tabular}

	  The argument \textsl{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
	  \texttt{D}\textsl{varname}\verb@_@\textsl{i} where
	  \textsl{varname} is the name of the original series and
	  \textsl{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. 

\subsection{eigengen}
\hypertarget{func-eigengen}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{A} (square matrix)\\
           & \textsl{\&U} (reference to matrix, or \texttt{null})\\
\end{tabular}

	  Computes the eigenvalues, and optionally the right eigenvectors, of
	  the \ensuremath{n\times n} matrix \textsl{A}.  If all the
	  eigenvalues are real, an \ensuremath{n\times 1} matrix is returned;
	  otherwise, the result is an \ensuremath{n\times 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 \verb@&@ (to indicate the
	  ``address'' of the matrix in question), in which case
	  an auxiliary result is written to that matrix, or the keyword
	  \texttt{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:

\begin{itemize}
\item 
	      If the \ensuremath{i}-th eigenvalue is real, the
	      \ensuremath{i}-th column of \ensuremath{U} will contain the
	      corresponding eigenvector;

\item 
	      If the \ensuremath{i}-th eigenvalue is complex, the
	      \ensuremath{i}-th column of \textsl{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.

\end{itemize}

	  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 \ensuremath{n},
	  because the conjugate eigenvector is skipped.

	  See also \hyperlink{func-eigensym}{eigensym}, \hyperlink{func-qrdecomp}{qrdecomp}, \hyperlink{func-svd}{svd}.

\subsection{eigensym}
\hypertarget{func-eigensym}{}

\begin{tabular}{ll}
Output:     & column vector\\
Arguments:  & \textsl{A} (square matrix)\\
           & \textsl{\&U} (reference to matrix, or \texttt{null})\\
\end{tabular}

	  Computes the eigenvalues, and optionally the right eigenvectors, of
	  the \ensuremath{n\times n} symmetrix matrix \textsl{A}; the
	  second argument must be either the name of an existing matrix
	  preceded by \verb@&@ (to indicate the ``address''
	  of the matrix in question), in which case an auxiliary result is
	  written to that matrix, or the keyword \texttt{null}, in which
	  case the auxiliary result is not produced.

	  If the second argument is not \texttt{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 \hyperlink{func-eigengen}{eigengen}, \hyperlink{func-qrdecomp}{qrdecomp}, \hyperlink{func-svd}{svd}.

\subsection{exp}
\hypertarget{func-exp}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Exponential. Note: in case of matrices, the function acts element
	  by element. For the matrix exponential function, see \hyperlink{func-mexp}{mexp}.

\subsection{fdjac}
\hypertarget{func-fdjac}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{b} (column vector)\\
           & \textsl{s} (string)\\
\end{tabular}

	  Calculates the (forward-difference approximation to the) Jacobian
	  associated with the vector \textsl{b} and the
	  transformation function defined by the function call in the string
	  \textsl{s}. For more details and examples see the chapter
	  on special functions in \texttt{genr} in 
	  \GUG{}.

	  See also \hyperlink{func-BFGSmax}{BFGSmax}.

\subsection{fft}
\hypertarget{func-fft}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Discrete real Fourier transform. If the input matrix
	  \textsl{X} has \ensuremath{n} columns, the output has
	  2\ensuremath{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
	  \texttt{fft} for each vector separately.  
	  See also \hyperlink{func-ffti}{ffti}.

\subsection{ffti}
\hypertarget{func-ffti}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Inverse discrete real Fourier transform. It is assumed that
	  \textsl{X} contains \ensuremath{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\ensuremath{n}. A matrix with \ensuremath{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 \texttt{ffti} for each vector separately.
	  See also \hyperlink{func-fft}{fft}.

\subsection{firstobs}
\hypertarget{func-firstobs}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  First non-missing observation for the variable
	  \textsl{y}. Note that if some form of subsampling is
	  in effect, the value returned may be smaller than the dollar
	  variable \hyperlink{func-dolt1}{\$t1}. 
	  See also \hyperlink{func-lastobs}{lastobs}.

\subsection{floor}
\hypertarget{func-floor}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{y} (scalar, series or matrix)\\
\end{tabular}

	  Floor function: returns the greatest integer less than or equal
	  to \textsl{x}. Note: \hyperlink{func-int}{int} and
	  \texttt{floor} differ in their effect for negative arguments:
	  \texttt{int(-3.5)} gives $-$3, while
	  \texttt{floor(-3.5)} gives $-$4. 

\subsection{fracdiff}
\hypertarget{func-fracdiff}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{y} (series)\\
           & \textsl{d} (scalar)\\
\end{tabular}

	    \[
	    \Delta^d y_t = y_t - \sum_{i=1}^{\infty} \psi_i y_{t-i}
	    \]
	  where
	    \[\psi_i = \frac{\Gamma(i-d)}{\Gamma(-d) \Gamma(i+1)}\]

	  Note that in theory fractional differentiation is an infinitely
	  long filter. In practice, presample values of
	  \ensuremath{y}\ensuremath{_{t}} are assumed to be zero.

\subsection{gammafun}
\hypertarget{func-gammafun}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Returns the gamma function of \textsl{x}. 

\subsection{genpois}
\hypertarget{func-genpois}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{$\mu$} (scalar or series)\\
\end{tabular}

	  Generates a series of Poisson pseudo-random variates. If $\mu$ is
	  a scalar, all the elements are drawn from the same distribution
	  \[ P(x_t = a) = e^{-\mu} \frac{\mu^{a}}{a!} \] 
	  Otherwise, if $\mu$ is a series, the above becomes 
	  \[ P(x_t = a) = e^{-\mu_t} \frac{\mu_t^{a}}{a!} \]

	  See also \hyperlink{func-randgen}{randgen}, \hyperlink{func-normal}{normal}, \hyperlink{func-uniform}{uniform}, \hyperlink{func-mnormal}{mnormal}, \hyperlink{func-muniform}{muniform}.

\subsection{getenv}
\hypertarget{func-getenv}{}

\begin{tabular}{ll}
Output:     & string\\
Argument:   & \textsl{s} (string)\\
\end{tabular}

	  If an environment variable by the name of \textsl{s}
	  is defined, returns the value of that variable, otherwise
	  returns an empty string.

\subsection{gini}
\hypertarget{func-gini}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Returns Gini's inequality index for the series
	  \textsl{y}.

\subsection{ginv}
\hypertarget{func-ginv}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{A} (matrix)\\
\end{tabular}

	  Returns \ensuremath{A}\ensuremath{^{+}}, the Moore--Penrose 
	  or generalized inverse of \textsl{A}, computed
	  via the singular value decomposition.

	  This matrix has the properties
	  \begin{eqnarray*}
	  A A^+ A & = & A \\
	  A^+ A A^+ & = & A^+ 
	  \end{eqnarray*}
	  Moreover, the products $A^+ A$ and $A A^+$ are
	  symmetric by construction.

	  See also \hyperlink{func-inv}{inv}, \hyperlink{func-svd}{svd}.

\subsection{hpfilt}
\hypertarget{func-hpfilt}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Returns the cycle from the Hodrick--Prescott filter applied
	  to series \textsl{y}.  See \GUG{} for details. 
	  See also \hyperlink{func-bkfilt}{bkfilt}.

\subsection{I}
\hypertarget{func-I}{}

\begin{tabular}{ll}
Output:     & square matrix\\
Argument:   & \textsl{n} (scalar)\\
\end{tabular}

	  Returns an identity matrix with \textsl{n} rows and
	  columns.

\subsection{imaxc}
\hypertarget{func-imaxc}{}

\begin{tabular}{ll}
Output:     & row vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the row indices of the maxima of the columns of
	  \textsl{X}. 

	  See also \hyperlink{func-imaxr}{imaxr}, \hyperlink{func-iminc}{iminc}, \hyperlink{func-maxc}{maxc}.

\subsection{imaxr}
\hypertarget{func-imaxr}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the column indices of the maxima of the rows of
	  \textsl{X}. 

	  See also \hyperlink{func-imaxc}{imaxc}, \hyperlink{func-iminr}{iminr}, \hyperlink{func-maxr}{maxr}.

\subsection{iminc}
\hypertarget{func-iminc}{}

\begin{tabular}{ll}
Output:     & row vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the row indices of the minima of the columns of
	  \ensuremath{X}. 

	  See also \hyperlink{func-iminr}{iminr}, \hyperlink{func-imaxc}{imaxc}, \hyperlink{func-minc}{minc}.

\subsection{iminr}
\hypertarget{func-iminr}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the column indices of the mimima of the rows of
	  \ensuremath{X}. 

	  See also \hyperlink{func-iminc}{iminc}, \hyperlink{func-imaxr}{imaxr}, \hyperlink{func-minr}{minr}.

\subsection{infnorm}
\hypertarget{func-infnorm}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the $\infty$-norm of the $r\times c$ matrix
	  \textsl{X}, namely, 
	    \[\| X \|_{\infty} = \max_i \sum_{j=1}^c |X_{ij}|\]

	  See also \hyperlink{func-onenorm}{onenorm}.

\subsection{int}
\hypertarget{func-int}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Truncates the fractional part of \textsl{x}. Note:
	  \texttt{int} and \hyperlink{func-floor}{floor} differ in their effect
	  for negative arguments: \texttt{int(-3.5)} gives $-$3,
	  while \texttt{floor(-3.5)} gives $-$4. 
	  See also \hyperlink{func-ceil}{ceil}.

\subsection{inv}
\hypertarget{func-inv}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{A} (square matrix)\\
\end{tabular}

	  Returns the inverse of \textsl{A}. If
	  \textsl{A} is singular or not square, an error message
	  is produced and nothing is returned. Note that gretl checks
	  automatically the structure of \textsl{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 \hyperlink{func-ginv}{ginv}, \hyperlink{func-invpd}{invpd}.

\subsection{invcdf}
\hypertarget{func-invcdf}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Arguments:  & \textsl{c} (character)\\
           & \textsl{\dots{}} (see below)\\
           & \textsl{p} (scalar, series or matrix)\\
\end{tabular}

	  Inverse cumulative distribution function calculator. Returns
	  \ensuremath{x} such that
	  $P(X \le x) = p$, where the distribution \ensuremath{X}
	  is determined by the character \textsl{c}; Between the
	  arguments \textsl{c} and \textsl{p}, zero or
	  more additional arguments are required to specify the parameters
	  of the distribution, as follows.

	  \begin{center} 
	  \begin{tabular}{llll} 
	  \textit{Distribution} & code, $c$ &
	  \textit{Arg} 2 & \textit{Arg} 3 \\[4pt] 
	  Standard normal & \texttt{z}, \texttt{n} or \texttt{N} &
	  -- & -- \\ 
	  Student's $t$ (central) & \texttt{t} & 
	  degrees of freedom & -- \\ 
	  Chi square & \texttt{c}, \texttt{x} or \texttt{X} & 
	  degrees of freedom & -- \\
	  Snedecor's $F$ & \texttt{f} or \texttt{F} & 
	  df (num.) & df (den.) \\ 
	  Binomial & \texttt{b} or \texttt{B} & 
	  $p$ & $n$ \\
	  \end{tabular}
	  \end{center}

	  See also \hyperlink{func-cdf}{cdf}, \hyperlink{func-critical}{critical}, \hyperlink{func-pvalue}{pvalue}.

\subsection{invpd}
\hypertarget{func-invpd}{}

\begin{tabular}{ll}
Output:     & square matrix\\
Argument:   & \textsl{A} (symmetric matrix)\\
\end{tabular}

	  Returns the inverse of the symmetric, positive definite matrix
	  \textsl{A}.   This function is slightly faster than
	  \hyperlink{func-inv}{inv} for large matrices, since no check for
	  symmetry is performed; for that reason it should be used with
	  care.

\subsection{islist}
\hypertarget{func-islist}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{s} (string)\\
\end{tabular}

	  Returns 1 if \textsl{s} is the identifier for a
	  currently defined list, otherwise 0.
	  See also \hyperlink{func-isnull}{isnull}, \hyperlink{func-isseries}{isseries}, \hyperlink{func-isstring}{isstring}.

\subsection{isnull}
\hypertarget{func-isnull}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{s} (string)\\
\end{tabular}

	  Returns 0 if \textsl{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 \hyperlink{func-islist}{islist}, \hyperlink{func-isseries}{isseries}, \hyperlink{func-isstring}{isstring}.

\subsection{isseries}
\hypertarget{func-isseries}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{s} (string)\\
\end{tabular}

	  Returns 1 if \textsl{s} is the identifier for a
	  currently defined series, otherwise 0.
	  See also \hyperlink{func-islist}{islist}, \hyperlink{func-isnull}{isnull}, \hyperlink{func-isstring}{isstring}.

\subsection{isstring}
\hypertarget{func-isstring}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{s} (string)\\
\end{tabular}

	  Returns 1 if \ensuremath{s} is the identifier for a currently
	  defined string, otherwise 0.
	  See also \hyperlink{func-islist}{islist}, \hyperlink{func-isnull}{isnull}, \hyperlink{func-isseries}{isseries}.

\subsection{lags}
\hypertarget{func-lags}{}

\begin{tabular}{ll}
Output:     & list\\
Arguments:  & \textsl{p} (scalar)\\
           & \textsl{y} (series or list)\\
\end{tabular}

	  Generates lags 1 to \textsl{p} of the series
	  \textsl{y}, or if \textsl{y} is a list, of all
	  variables in the list.  If \textsl{p} = 0, the maximum
	  lag defaults to the periodicity of the data; otherwise
	  \textsl{p} must be positive.

	  The generated variables are automatically named according to
	  the template \textsl{varname}\verb@_@\textsl{i} where
	  \textsl{varname} is the name of the original series and
	  \textsl{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.  

\subsection{lastobs}
\hypertarget{func-lastobs}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Last non-missing observation for the variable
	  \textsl{y}. Note that if some form of subsampling is
	  in effect, the value returned may be larger than the dollar
	  variable \hyperlink{func-dolt2}{\$t2}.
	  See also \hyperlink{func-firstobs}{firstobs}.

\subsection{ldet}
\hypertarget{func-ldet}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{A} (square matrix)\\
\end{tabular}

	  Returns the natural log of the determinant of \ensuremath{A},
	  computed via the LU factorization.
	  See also \hyperlink{func-det}{det}, \hyperlink{func-rcond}{rcond}.

\subsection{ldiff}
\hypertarget{func-ldiff}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{y} (series or list)\\
\end{tabular}

	  Computes log differences; starting values are set to
	  \texttt{NA}.

	  When a list is returned, the individual variables are
	  automatically named according to the template
	  \verb@ld_@\textsl{varname} where \textsl{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 \hyperlink{func-diff}{diff}, \hyperlink{func-sdiff}{sdiff}.

\subsection{lincomb}
\hypertarget{func-lincomb}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{L} (list)\\
           & \textsl{b} (vector)\\
\end{tabular}

	  Computes a new series as a linear combination of the series in the
	  list \textsl{L}.  The coefficients are given by the vector
	  \textsl{b}, which must have length equal to the number of
	  series in \textsl{L}.

	  See also \hyperlink{func-wmean}{wmean}.

\subsection{ljungbox}
\hypertarget{func-ljungbox}{}

\begin{tabular}{ll}
Output:     & scalar\\
Arguments:  & \textsl{y} (series)\\
           & \textsl{p} (scalar)\\
\end{tabular}

	  Computes the Ljung--Box Q' statistic for the series
	  \textsl{y} using lag order \textsl{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
	  \textsl{p} degrees of freedom as a test of the null
	  hypothesis that the series \textsl{y} is serially
	  independent.
	  See also \hyperlink{func-pvalue}{pvalue}.

\subsection{lngamma}
\hypertarget{func-lngamma}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Log of the gamma function of \textsl{x}.

\subsection{log}
\hypertarget{func-log}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series, matrix or list)\\
\end{tabular}

	  Natural logarithm; produces \texttt{NA} for non-positive
	  values. Note: \texttt{ln} is an acceptable alias for
	  \texttt{log}.

	  When a list is returned, the individual variables are
	  automatically named according to the template
	  \verb@l_@\textsl{varname} where \textsl{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.

\subsection{log10}
\hypertarget{func-log10}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Base-10 logarithm; produces \texttt{NA} for non-positive
	  values.

\subsection{log2}
\hypertarget{func-log2}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Base-2 logarithm; produces \texttt{NA} for non-positive
	  values.

\subsection{lower}
\hypertarget{func-lower}{}

\begin{tabular}{ll}
Output:     & square matrix\\
Argument:   & \textsl{A} (matrix)\\
\end{tabular}

	  Returns an $n\times n$ lower triangular matrix \ensuremath{B}
	  for which $B_{ij} = A_{ij}$ if $i \ge j$, and 0 otherwise.

	  See also \hyperlink{func-upper}{upper}.

\subsection{lrvar}
\hypertarget{func-lrvar}{}

\begin{tabular}{ll}
Output:     & scalar\\
Arguments:  & \textsl{y} (series)\\
           & \textsl{k} (scalar)\\
\end{tabular}

	  Returns the long-run variance of \textsl{y},
	  calculated using a Bartlett kernel with window size
	  \textsl{k}. If \textsl{k} is
	  negative, \verb@int(T^(1/3))@ is used.

	  In formulae: 
	  \[ \hat{\omega}^2(k) = \frac{1}{T} \sum_{t=k}^{T-k}
	  \left[ \sum_{i=-k}^k w_i (y_t - \bar{X}) (y_{t-i} - \bar{Y})
	  \right] \] 
	  with 
	  \[ w_i = 1 - \frac{|i|}{k + 1} \]

\subsection{makemask}
\hypertarget{func-makemask}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Produces a column vector containing the observation numbers
	  corresponding to the non-zero entries in the series
	  \textsl{y}. This function is typically useful for
	  filtering out rows of a matrix built from data series.

\subsection{max}
\hypertarget{func-max}{}

\begin{tabular}{ll}
Output:     & scalar or series\\
Argument:   & \textsl{y} (series or list)\\
\end{tabular}

	  If the argument \textsl{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.

\subsection{maxc}
\hypertarget{func-maxc}{}

\begin{tabular}{ll}
Output:     & row vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the maxima of the columns of \textsl{X}.

	  See also \hyperlink{func-imaxc}{imaxc}, \hyperlink{func-maxr}{maxr}, \hyperlink{func-minc}{minc}.

\subsection{maxr}
\hypertarget{func-maxr}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the maxima of the rows of \textsl{X}. 

	  See also \hyperlink{func-imaxc}{imaxc}, \hyperlink{func-maxc}{maxc}, \hyperlink{func-minr}{minr}.

\subsection{mcorr}
\hypertarget{func-mcorr}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Computes a correlation matrix treating each column of
	  \textsl{X} as a variable. 
	  See also \hyperlink{func-corr}{corr}, \hyperlink{func-cov}{cov}, \hyperlink{func-mcov}{mcov}.

\subsection{mcov}
\hypertarget{func-mcov}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Computes a covariance matrix treating each column of
	  \textsl{X} as a variable. 
	  See also \hyperlink{func-corr}{corr}, \hyperlink{func-cov}{cov}, \hyperlink{func-mcorr}{mcorr}.

\subsection{mean}
\hypertarget{func-mean}{}

\begin{tabular}{ll}
Output:     & scalar or series\\
Argument:   & \textsl{x} (series or list)\\
\end{tabular}

	  If \textsl{x} is a series, returns the (scalar) sample
	  mean, skipping any missing observations.

	  If \textsl{x} is a list, returns a series \ensuremath{y}
	  such that \ensuremath{y}\ensuremath{_{t}} is the mean of the values of
	  the variables in the list at observation \ensuremath{t}, or
	  \texttt{NA} if there are any missing values at \ensuremath{t}.

\subsection{meanc}
\hypertarget{func-meanc}{}

\begin{tabular}{ll}
Output:     & row vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the means of the columns of \textsl{X}. 
	  See also \hyperlink{func-meanr}{meanr}, \hyperlink{func-sumc}{sumc}, \hyperlink{func-sdc}{sdc}.

\subsection{meanr}
\hypertarget{func-meanr}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the means of the rows of \textsl{X}. 
	  See also \hyperlink{func-meanc}{meanc}, \hyperlink{func-sumr}{sumr}.

\subsection{median}
\hypertarget{func-median}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  The median of the non-missing observations in series
	  \textsl{y}. 
	  See also \hyperlink{func-quantile}{quantile}.

\subsection{mexp}
\hypertarget{func-mexp}{}

\begin{tabular}{ll}
Output:     & square matrix\\
Argument:   & \textsl{A} (square matrix)\\
\end{tabular}

	  Matrix exponential, 
	  \[ e^A = \sum_{k=0}^{\infty} \frac{A^k}{k!}
	  = \frac{I}{0!} + \frac{A}{1!} + \frac{A^2}{2!} + \frac{A^3}{3!}
	  + \cdots\] 
	  (This series is sure to converge.) The algorithm used
	  is 11.3.1 from Golub and Van Loan (1996).

\subsection{min}
\hypertarget{func-min}{}

\begin{tabular}{ll}
Output:     & scalar or series\\
Argument:   & \textsl{y} (series or list)\\
\end{tabular}

	  If the argument \textsl{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.

\subsection{minc}
\hypertarget{func-minc}{}

\begin{tabular}{ll}
Output:     & row vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the minima of the columns of \textsl{X}.

	  See also \hyperlink{func-iminc}{iminc}, \hyperlink{func-maxc}{maxc}, \hyperlink{func-minr}{minr}.

\subsection{minr}
\hypertarget{func-minr}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the minima of the rows of \textsl{X}. 

	  See also \hyperlink{func-iminr}{iminr}, \hyperlink{func-maxr}{maxr}, \hyperlink{func-minc}{minc}.

\subsection{missing}
\hypertarget{func-missing}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar or series)\\
\end{tabular}

	  Returns a binary variable holding 1 if \textsl{x} is
	  \texttt{NA}. If \textsl{x} is a series, the
	  comparison is done element by element. 
	  See also \hyperlink{func-misszero}{misszero}, \hyperlink{func-ok}{ok}, \hyperlink{func-zeromiss}{zeromiss}.

\subsection{misszero}
\hypertarget{func-misszero}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar or series)\\
\end{tabular}

	  Converts \texttt{NA}s to zeros. If \textsl{x} is a
	  series, the conversion is done element by element. 
	  See also \hyperlink{func-missing}{missing}, \hyperlink{func-ok}{ok}, \hyperlink{func-zeromiss}{zeromiss}.

\subsection{mlag}
\hypertarget{func-mlag}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{p} (scalar)\\
\end{tabular}

	  Shifts up or down the elements of \textsl{X}. If $p
	  > 0$ the returned matrix $Y$ has typical element $Y_{i,j} =
	  X_{i-p,j}$ for $i \ge p$ and zero otherwise. In other words, the
	  columns of \textsl{X} are shifted down by
	  \textsl{p} rows and the first \textsl{p}
	  rows are filled with zeros. If \textsl{p} is a
	  negative number, \textsl{X} is shifted up and the last
	  rows are filled with zeros.

\subsection{mnormal}
\hypertarget{func-mnormal}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{r} (scalar)\\
           & \textsl{c} (scalar)\\
\end{tabular}

	  Returns a matrix with \textsl{r} rows and
	  \textsl{c} columns, filled with standard normal
	  pseudo-random variates. 
	  See also \hyperlink{func-normal}{normal}, \hyperlink{func-muniform}{muniform}.

\subsection{mols}
\hypertarget{func-mols}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{Y} (matrix)\\
           & \textsl{X} (matrix)\\
           & \textsl{\&U} (reference to matrix, or \texttt{null})\\
\end{tabular}

	  Returns a \ensuremath{k\times n} matrix of parameter estimates obtained
	  by OLS regression of the \ensuremath{T\times n} matrix
	  \textsl{Y} on the \ensuremath{T\times k} matrix
	  \textsl{X}. The Cholesky decomposition is used. If the
	  third argument is not \texttt{null}, the \ensuremath{T\times n} matrix
	  \textsl{U} will contain the residuals.

\subsection{movavg}
\hypertarget{func-movavg}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{x} (series)\\
           & \textsl{p} (scalar)\\
\end{tabular}

	  Computes the \textsl{p}-term moving average for
	  the series
	  \textsl{x}, that is $y_t = \frac{1}{p}
	  \sum_{i=0}^{p-1} x_{t-i}$.

	  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:

\begin{code}
	    tmp = movavg(x,3)
	    y = tmp(+1)

\end{code}

\subsection{mread}
\hypertarget{func-mread}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{s} (string)\\
\end{tabular}

	  Reads a matrix from a text file. The string \textsl{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:

\begin{itemize}
\item 
	      The columns must be separated by spaces or tab characters.

\item 
	      The decimal separator must be the dot character,
	      ``\texttt{.}''.

\item 
	      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.

\end{itemize}

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

	  See also \hyperlink{func-mwrite}{mwrite}.

\subsection{mshape}
\hypertarget{func-mshape}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{r} (scalar)\\
           & \textsl{c} (scalar)\\
\end{tabular}

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

	  See also \hyperlink{func-cols}{cols}, \hyperlink{func-rows}{rows}, \hyperlink{func-unvech}{unvech}, \hyperlink{func-vec}{vec}, \hyperlink{func-vech}{vech}.

\subsection{msortby}
\hypertarget{func-msortby}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{j} (scalar)\\
\end{tabular}

	  Returns a matrix in which the rows of \textsl{X}
	  are reordered by increasing value of the elements in
	  column \textsl{j}.

\subsection{muniform}
\hypertarget{func-muniform}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{r} (scalar)\\
           & \textsl{c} (scalar)\\
\end{tabular}

	  Returns a matrix with \textsl{r} rows and
	  \textsl{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
	  \texttt{muniform} to a scalar, as in 

\begin{code}
	  scalar x = muniform(1,1)

\end{code}

	  See also \hyperlink{func-mnormal}{mnormal}, \hyperlink{func-uniform}{uniform}.

\subsection{mwrite}
\hypertarget{func-mwrite}{}

\begin{tabular}{ll}
Output:     & scalar\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{s} (string)\\
\end{tabular}

	  Writes the matrix \textsl{X} to a plain text file
	  named \textsl{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 \textsl{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 \texttt{mwrite} command can be easily
	  read by other programs; see \GUG{} for
	  details.

	  See also \hyperlink{func-mread}{mread}.

\subsection{mxtab}
\hypertarget{func-mxtab}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{x} (series or vector)\\
           & \textsl{y} (series or vector)\\
\end{tabular}

	  Returns a matrix holding the cross tabulation of the values
	  contained in \textsl{x} (by row) and
	  \textsl{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 \hyperlink{func-values}{values}.

\subsection{nelem}
\hypertarget{func-nelem}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{L} (list)\\
\end{tabular}

	  Returns the number of items in list \textsl{L}.

\subsection{nobs}
\hypertarget{func-nobs}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Returns the number of non-missing observations for the variable
	  \textsl{y} in the currently selected sample.

\subsection{normal}
\hypertarget{func-normal}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{$\mu$} (scalar)\\
           & \textsl{$\sigma$} (scalar)\\
\end{tabular}

	  Generates a series of Gaussian pseudo-random variates with mean
	  $\mu$ and standard deviation $\sigma$. If no arguments are
	  supplied, standard normal variates \ensuremath{N}(0,1) are
	  produced.

	  See also \hyperlink{func-randgen}{randgen}, \hyperlink{func-normal}{normal}, \hyperlink{func-genpois}{genpois}, \hyperlink{func-mnormal}{mnormal}, \hyperlink{func-muniform}{muniform}.

\subsection{nullspace}
\hypertarget{func-nullspace}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{A} (matrix)\\
\end{tabular}

	  Computes the right nullspace of \textsl{A}, via the
	  singular value decomposition: the result is a matrix $B$ such
	  that $AB = [0]$, except when $A$ has full column rank, in which
	  case an empty matrix is returned. Otherwise, if $A$ is $m \times
	  n$, $B$ will be an $n \times (n-r)$ matrix, where $r$ is the
	  rank of $A$.  

	  See also \hyperlink{func-rank}{rank}, \hyperlink{func-svd}{svd}.

\subsection{obs}
\hypertarget{func-obs}{}

\begin{tabular}{ll}
Output:     & series\\
\end{tabular}

	  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 \texttt{t} instead of
	  \texttt{obs} with the same effect.

	  See also \hyperlink{func-obsnum}{obsnum}.

\subsection{obsnum}
\hypertarget{func-obsnum}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{s} (string)\\
\end{tabular}

	  Returns an integer corresponding to the observation specified by
	  the string \ensuremath{s}. Note that the result is invariant to
	  subsampling. This function is especially useful with time-series
	  datasets.  For example, the following code

\begin{code}
	  open denmark 
	  k = obsnum(1980:1)

\end{code}

	  yields \texttt{k = 25}, indicating that the first quarter of
	  1980 is the 25th observation in the \texttt{denmark} dataset.

	  See also \hyperlink{func-obs}{obs}.

\subsection{ok}
\hypertarget{func-ok}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or list)\\
\end{tabular}

	  Returns a binary variable holding 1 if \ensuremath{x} is not
	  \texttt{NA}. If \ensuremath{x} is a series, the comparison is
	  done element by element. If \ensuremath{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 \hyperlink{func-missing}{missing}, \hyperlink{func-misszero}{misszero}, \hyperlink{func-zeromiss}{zeromiss}.

\subsection{onenorm}
\hypertarget{func-onenorm}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the 1-norm of the $r \times c$ matrix
	  \textsl{X}: 
	  \[\| X \|_1 = \max_j \sum_{i=1}^r |X_{ij}| \]

	  See also \hyperlink{func-infnorm}{infnorm}, \hyperlink{func-rcond}{rcond}.

\subsection{ones}
\hypertarget{func-ones}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{r} (scalar)\\
           & \textsl{c} (scalar)\\
\end{tabular}

	  Outputs a matrix with \ensuremath{r} rows and \ensuremath{c}
	  columns, filled with ones.

	  See also \hyperlink{func-seq}{seq}, \hyperlink{func-zeros}{zeros}.

\subsection{orthdev}
\hypertarget{func-orthdev}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Only applicable if the currently open dataset has a panel
	  structure. Computes the forward orthogonal deviations for
	  variable \textsl{y}, that is 
	  \[ \tilde{y}_{i,t} =
	  \sqrt{ \frac{T_i - t}{T_i - t + 1}} \left( y_{i,t} -
	  \frac{1}{T_i - t} \sum_{s=t+1}^{T_i} y_{i,s} \right) \]

	  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
	  \ensuremath{t} is the deviation that, strictly speaking, belongs at
	  \ensuremath{t} $-$ 1).  That way one loses the first observation
	  in each time series, not the last.

	  See also \hyperlink{func-diff}{diff}.

\subsection{pdf}
\hypertarget{func-pdf}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Arguments:  & \textsl{c} (character)\\
           & \textsl{\dots{}} (see below)\\
           & \textsl{x} (scalar, series or matrix)\\
Examples:    & \texttt{f1 = pdf(N, -2.5)} \\ 
 & \texttt{f2 = pdf(X, 3, y)} \\ 
 & \texttt{f3 = pdf(W, shape, scale, y)}
\end{tabular}

	  Probability density function calculator. Returns the density at
	  \textsl{x} of the distribution identified by the code
	  \textsl{c}.  See \hyperlink{func-cdf}{cdf} for details of the
	  required arguments.  The distributions supported by the
	  \texttt{pdf} function are the normal, Student's \ensuremath{t},
	  chi-square, \ensuremath{F}, Gamma and Weibull.

	  For the normal distribution, see also \hyperlink{func-dnorm}{dnorm}.

\subsection{pmax}
\hypertarget{func-pmax}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Only applicable if the currently open dataset has a panel
	  structure. Returns the per-unit maximum for variable
	  \textsl{y}.

	  Missing values are skipped. 
	  See also \hyperlink{func-pmin}{pmin}, \hyperlink{func-pmean}{pmean}, \hyperlink{func-pnobs}{pnobs}, \hyperlink{func-psd}{psd}.

\subsection{pmean}
\hypertarget{func-pmean}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Only applicable if the currently open dataset has a panel
	  structure. Computes the per-unit mean for variable
	  \textsl{y}; that is, 
	  \[ \bar{y}_i = \frac{1}{T_i} \sum_{t=1}^{T_i} y_{i,t}\] 
	  where $T_i$ is the number of valid
	  observations for unit $i$.

	  Missing values are skipped. 
	  See also \hyperlink{func-pmax}{pmax}, \hyperlink{func-pmin}{pmin}, \hyperlink{func-pnobs}{pnobs}, \hyperlink{func-psd}{psd}.
\subsection{pmin}
\hypertarget{func-pmin}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Only applicable if the currently open dataset has a panel
	  structure. Returns the per-unit minimum for variable
	  \textsl{y}.

	  Missing values are skipped. 
	  See also \hyperlink{func-pmax}{pmax}, \hyperlink{func-pmean}{pmean}, \hyperlink{func-pnobs}{pnobs}, \hyperlink{func-psd}{psd}.

\subsection{pnobs}
\hypertarget{func-pnobs}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Only applicable if the currently open dataset has a panel
	  structure. Returns for each unit the number of non-missing
	  cases for the variable \textsl{y}.

	  Missing values are skipped. 
	  See also \hyperlink{func-pmax}{pmax}, \hyperlink{func-pmin}{pmin}, \hyperlink{func-pmean}{pmean}, \hyperlink{func-psd}{psd}.
\subsection{polroots}
\hypertarget{func-polroots}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{a} (vector)\\
\end{tabular}

	  Finds the roots of a polynomial.  If the polynomial is of degree
	  \ensuremath{p}, the vector \textsl{a} should contain
	  \ensuremath{p} + 1 coefficients in ascending order, i.e.{} starting
	  with the constant and ending with the coefficient on
	  \ensuremath{x}\ensuremath{^{p}}.

	  If all the roots are real they are returned in a column vector of
	  length \ensuremath{p}, otherwise a \ensuremath{p\times 2} matrix
	  is returned, the real parts in the first column and the imaginary
	  parts in the second.

\subsection{princomp}
\hypertarget{func-princomp}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{p} (scalar)\\
\end{tabular}

	  Let the matrix \textsl{X} be \ensuremath{T\times k}, containing
	  \ensuremath{T} observations on \ensuremath{k} variables.  The
	  argument \textsl{p} must be a positive integer less than
	  or equal to \ensuremath{k}. This function returns a \ensuremath{T\times p} matrix, \ensuremath{P}, holding the first \ensuremath{p}
	  principal components of \textsl{X}.

	  The elements of $P$ are computed as 
	  \[ P_{tj} = \sum_{i=1}^{k} Z_{ti} \, v^{(j)}_i \] 
	  where $Z_{ti}$ is the standardized value
	  of variable $i$ at observation $t$, $Z_{ti} = (X_{ti} -
	  \bar{X}_i) / \hat{\sigma}_i$, and $v^{(j)}$ is the $j$th
	  eigenvector of the correlation matrix of the $X_i$s, with the
	  eigenvectors ordered by decreasing value of the corresponding
	  eigenvalues.

	  See also \hyperlink{func-eigensym}{eigensym}.

\subsection{psd}
\hypertarget{func-psd}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Only applicable if the currently open dataset has a panel
	  structure. Computes the per-unit sample standard deviation for
	  variable \ensuremath{y}, that is 
	  \[ \sigma_i = \sqrt{\frac{1}{T_i - 1} \sum_{t=1}^{T_i} 
	  (y_{i,t} - \bar{y}_i)^2 } \]
	  The above formula holds for $T_i \ge 2$, where $T_i$ is the
	  number of valid observations for unit $i$; if $T_i = 0$,
	  \texttt{NA} is returned; if $T_i = 1$, 0 is returned.

	  Note: this function makes it possible to check whether a given
	  variable (say, \texttt{X}) is time-invariant via the condition
	  \texttt{max(psd(X)) = 0}.

	  See also \hyperlink{func-pmax}{pmax}, \hyperlink{func-pmin}{pmin}, \hyperlink{func-pmean}{pmean}, \hyperlink{func-pnobs}{pnobs}.

\subsection{pvalue}
\hypertarget{func-pvalue}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Arguments:  & \textsl{c} (character)\\
           & \textsl{\dots{}} (see below)\\
           & \textsl{x} (scalar, series or matrix)\\
Examples:    & \texttt{p1 = pvalue(z, 2.2)} \\ 
 & \texttt{p2 = pvalue(X, 3, 5.67)} \\ 
 & \texttt{p2 = pvalue(F, 3, 30, 5.67)}
\end{tabular}

	  \ensuremath{P}-value calculator. Returns 
	  $P(X > x)$,
	  where the distribution \ensuremath{X} is determined by the
	  character \textsl{c}. Between the arguments
	  \textsl{c} and \textsl{x}, zero or more
	  additional arguments are required to specify the parameters of
	  the distribution; see \hyperlink{func-cdf}{cdf} for details.  The
	  distributions supported by the \texttt{pval} function are
	  the standard normal, \ensuremath{t}, Chi square, \ensuremath{F},
	  gamma, binomial, Poisson and Weibull.

	  See also \hyperlink{func-critical}{critical}, \hyperlink{func-invcdf}{invcdf}.

\subsection{qform}
\hypertarget{func-qform}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{x} (matrix)\\
           & \textsl{A} (symmetric matrix)\\
\end{tabular}

	  Computes the quadratic form 
	  $Y = x A x'$. Using this function instead of ordinary
	  matrix multiplication guarantees more speed and better accuracy.
	  If \textsl{x} and \textsl{A} are not
	  conformable, or \textsl{A} is not symmetric, an error
	  is returned.

\subsection{qnorm}
\hypertarget{func-qnorm}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Returns quantiles for the standard normal distribution. If
	  \textsl{x} is not between 0 and 1, \texttt{NA} is
	  returned. 
	  See also \hyperlink{func-cnorm}{cnorm}, \hyperlink{func-dnorm}{dnorm}.

\subsection{qrdecomp}
\hypertarget{func-qrdecomp}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{\&R} (reference to matrix, or \texttt{null})\\
\end{tabular}

	  Computes the QR decomposition of an \ensuremath{m\times n} matrix
	  \textsl{X}, that is \ensuremath{X = QR} where
	  \ensuremath{Q} is an \ensuremath{m\times n} orthogonal matrix and
	  \ensuremath{R} is an \ensuremath{n\times n} upper triangular matrix. The
	  matrix \ensuremath{Q} is returned directly, while \ensuremath{R} can
	  be retrieved via the optional second argument.

	  See also \hyperlink{func-eigengen}{eigengen}, \hyperlink{func-eigensym}{eigensym}, \hyperlink{func-svd}{svd}.

\subsection{quantile}
\hypertarget{func-quantile}{}

\begin{tabular}{ll}
Output:     & scalar or row vector\\
Arguments:  & \textsl{y} (series or matrix)\\
           & \textsl{p} (scalar between 0 and 1)\\
\end{tabular}

	  Given a series argument, returns the
	  \textsl{p}-quantile for the series. For example, when
	  \ensuremath{p} = 0.5, the median is returned. Given a
	  matrix argument, returns a row vector containing the 
	  \textsl{p}-quantiles for the columns of 
	  \textsl{y}; that is, each column is treated
	  as a series.

	  For a series of length $n$, the $p$-quantile, $q$, is defined
	  as:
	  \[q = y_{[k]} + (n \cdot p - k) (y_{[k+1]} - y_{[k]})\] 
	  where $k$ is the integer part of $n \cdot p$ and 
	  $y_{[i]}$ is the $i$-th element of the series when
	  sorted from smallest to largest.

\subsection{rank}
\hypertarget{func-rank}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the rank of \textsl{X}, numerically computed
	  via the singular value decomposition. 
	  See also \hyperlink{func-svd}{svd}.

\subsection{ranking}
\hypertarget{func-ranking}{}

\begin{tabular}{ll}
Output:     & series\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Returns a series with the ranks of \ensuremath{y}. The rank for
	  observation \ensuremath{i} is the number of elements in the
	  series that are less than \ensuremath{y}\ensuremath{_{i}} plus one
	  half the number of elements in the series that are equal to
	  \ensuremath{y}\ensuremath{_{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.

	  Formally, 
	  \[ \mathrm{rank}(y_i) = 1 + \sum_{j \ne i} \left[
	  I(y_j < y_i) + 0.5 \cdot I(y_j = y_i) \right] \] 
	  where $I$ denotes the indicator function.

	  See also \hyperlink{func-sort}{sort}, \hyperlink{func-sortby}{sortby}.

\subsection{randgen}
\hypertarget{func-randgen}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{c} (character)\\
           & \textsl{a} (scalar)\\
           & \textsl{b} (scalar)\\
Examples:    & \texttt{series x = randgen(u, 0, 100)} \\ 
 & \texttt{series t14 = randgen(t, 14)} \\ 
 & \texttt{series y = randgen(B, 0.6, 30)} \\ 
 & \texttt{series g = randgen(G, 1, 1)}
\end{tabular}

	  All-purpose random number generator. The parameter
	  \textsl{c} is a character, which specifies from which
	  distribution the pseudo-random numbers should be drawn;
	  \textsl{a} and, in some cases, \textsl{b}
	  gauge the shape of the distribution.

	  \begin{center}
	  \begin{tabular}{llll}
	  \textbf{Distribution} & \textsl{c} & \textsl{a} & \textsl{b} \\[4pt]
	  Uniform (continuous) & \texttt{u} or \texttt{U} & minimum & maximum\\
	  Normal & \texttt{z}, \texttt{n} or \texttt{N} & mean & standard deviation\\
	  Student's $t$ & \texttt{t} & degrees of freedom & --\\
	  Chi square & \texttt{c}, \texttt{x} or \texttt{X} & degrees of freedom & --\\
	  Snedecor's $F$ & \texttt{f} or \texttt{F} & df (num.) & df (den.)\\
	  Gamma & \texttt{g} or \texttt{G} & shape & scale \\
	  Binomial & \texttt{b} or \texttt{B} & $p$ & $n$ \\
	  Poisson & \texttt{p} or \texttt{P} & mean & -- \\
	  Weibull & \texttt{w} or \texttt{W} & shape & scale
	  \end{tabular}
	  \end{center}

	  See also \hyperlink{func-normal}{normal}, \hyperlink{func-uniform}{uniform}, \hyperlink{func-genpois}{genpois}.

\subsection{rcond}
\hypertarget{func-rcond}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{A} (square matrix)\\
\end{tabular}

	  Returns the reciprocal condition number for \textsl{A}
	  with respect to the 1-norm.  In many circumstances, this is a better
	  measure of the sensitivity of \textsl{A} to numerical
	  operations such as inversion than the determinant.

	  Given that \ensuremath{A} is non-singular, we may define
	  \[\kappa(A) = ||A||_1 \cdot ||A^{-1}||_1\] 
	  This function returns $\kappa(A)^{-1}$.

	  See also \hyperlink{func-det}{det}, \hyperlink{func-ldet}{ldet}, \hyperlink{func-onenorm}{onenorm}.

\subsection{readfile}
\hypertarget{func-readfile}{}

\begin{tabular}{ll}
Output:     & string\\
Argument:   & \textsl{fname} (string)\\
\end{tabular}

	  If a file by the name of \textsl{fname} exists and
	  is readable, returns a string containing the content of
	  this file, otherwise flags an error.  

	  Also see the \hyperlink{cmd-sscanf}{sscanf} command.

\subsection{resample}
\hypertarget{func-resample}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (series or matrix)\\
\end{tabular}

	  Resamples from \textsl{x} with replacement.  In the
	  case of a series argument, each value of the returned series,
	  \ensuremath{y}\ensuremath{_{t}}, is drawn from among all the values
	  of \ensuremath{x}\ensuremath{_{t}} with equal probability.  When
	  a matrix argument is given, each row of the returned matrix
	  is drawn from the rows of \textsl{x} with equal
	  probability.

\subsection{round}
\hypertarget{func-round}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Rounds to the nearest integer. Note that when \ensuremath{x}
	  lies halfway between two integers, rounding is done "away
	  from zero", so for example 2.5 rounds to 3, but 
	  \texttt{round(-3.5)} gives $-$4. This is a common
	  convention in spreadsheet programs, but other software may
	  yield different results.
	  See also \hyperlink{func-ceil}{ceil}, \hyperlink{func-floor}{floor}, \hyperlink{func-int}{int}.

\subsection{rows}
\hypertarget{func-rows}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Number of rows of the matrix \textsl{X}.  
	  See also \hyperlink{func-cols}{cols}, \hyperlink{func-mshape}{mshape}, \hyperlink{func-unvech}{unvech}, \hyperlink{func-vec}{vec}, \hyperlink{func-vech}{vech}.

\subsection{sd}
\hypertarget{func-sd}{}

\begin{tabular}{ll}
Output:     & scalar or series\\
Argument:   & \textsl{x} (series or list)\\
\end{tabular}

	  If \textsl{x} is a series, returns the (scalar) sample
	  standard deviation, skipping any missing observations.

	  If \textsl{x} is a list, returns a series \ensuremath{y}
	  such that \ensuremath{y}\ensuremath{_{t}} is the sample standard
	  deviation of the values of the variables in the list at observation
	  \ensuremath{t}, or \texttt{NA} if there are any missing values at
	  \ensuremath{t}.

	  See also \hyperlink{func-var}{var}.

\subsection{sdc}
\hypertarget{func-sdc}{}

\begin{tabular}{ll}
Output:     & row vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the standard deviations of the columns of
	  \textsl{X} (with no degrees of freedom correction). 
	  See also \hyperlink{func-meanc}{meanc}, \hyperlink{func-sumc}{sumc}.

\subsection{sdiff}
\hypertarget{func-sdiff}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{y} (series or list)\\
\end{tabular}

	  Computes seasonal differences: $y_t - y_{t-k}$, where
	  \ensuremath{k} is the periodicity of the current dataset (see
	  \hyperlink{func-dolpd}{\$pd}). Starting values are set to
	  \texttt{NA}.

	  When a list is returned, the individual variables are
	  automatically named according to the template
	  \verb@sd_@\textsl{varname} where \textsl{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 \hyperlink{func-diff}{diff}, \hyperlink{func-ldiff}{ldiff}.

\subsection{selifc}
\hypertarget{func-selifc}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{A} (matrix)\\
           & \textsl{b} (row vector)\\
\end{tabular}

	  Selects from \textsl{A} only the columns for which
	  the corresponding element of \textsl{b} is
	  non-zero. \textsl{b} must be a row vector with
	  the same number of columns as \textsl{A}.

	  See also \hyperlink{func-selifr}{selifr}.

\subsection{selifr}
\hypertarget{func-selifr}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{A} (matrix)\\
           & \textsl{b} (column vector)\\
\end{tabular}

	  Selects from \textsl{A} only the rows for which
	  the corresponding element of \textsl{b} is
	  non-zero. \textsl{b} must be a column vector with
	  the same number of rows as \textsl{A}.

	  See also \hyperlink{func-selifc}{selifc}, \hyperlink{func-trimr}{trimr}.

\subsection{seq}
\hypertarget{func-seq}{}

\begin{tabular}{ll}
Output:     & row vector\\
Arguments:  & \textsl{a} (scalar)\\
           & \textsl{b} (scalar)\\
\end{tabular}

	  Returns a row vector filled with consecutive integers, with
	  \textsl{a} as first element and \textsl{b}
	  last. If \textsl{a} is greater than
	  \textsl{b} the sequence will be decreasing. If either
	  argument is not integral its fractional part is discarded.

	  See also \hyperlink{func-ones}{ones}, \hyperlink{func-zeros}{zeros}.

\subsection{sin}
\hypertarget{func-sin}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Sine.  
	  See also \hyperlink{func-cos}{cos}, \hyperlink{func-tan}{tan}, \hyperlink{func-atan}{atan}.

\subsection{sort}
\hypertarget{func-sort}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (series or vector)\\
\end{tabular}

	  Sorts \textsl{x} in ascending order, skipping
	  observations with missing values when \ensuremath{x} is a
	  series.  
	  See also \hyperlink{func-dsort}{dsort}, \hyperlink{func-values}{values}.
	  For matrices specifically, see \hyperlink{func-msortby}{msortby}.

\subsection{sortby}
\hypertarget{func-sortby}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{y1} (series)\\
           & \textsl{y2} (series)\\
\end{tabular}

	  Returns a series containing the elements of
	  \textsl{y2} sorted by increasing value of the first
	  argument, \textsl{y1}. 
	  See also \hyperlink{func-sort}{sort}, \hyperlink{func-ranking}{ranking}.

\subsection{sqrt}
\hypertarget{func-sqrt}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Square root of \textsl{x}; produces \texttt{NA} for
	  negative values.

\subsection{sst}
\hypertarget{func-sst}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Sum of squared deviations from the mean for the non-missing
	  observations in series \textsl{y}.
	  See also \hyperlink{func-var}{var}.

\subsection{strlen}
\hypertarget{func-strlen}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{s} (string)\\
\end{tabular}

	  Returns the number of characters in \textsl{s}.

\subsection{strstr}
\hypertarget{func-strstr}{}

\begin{tabular}{ll}
Output:     & string\\
Arguments:  & \textsl{s1} (string)\\
           & \textsl{s2} (string)\\
\end{tabular}

	  Searches \textsl{s1} for an occurrence of the string
	  \textsl{s2}.  If a match is found, returns a copy of the
	  portion of \textsl{s1} that starts with
	  \textsl{s2}, otherwise returns an empty string.

\subsection{sum}
\hypertarget{func-sum}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{y} (series)\\
\end{tabular}

	  Sum of the non-missing observations in series
	  \textsl{y}.

\subsection{sumc}
\hypertarget{func-sumc}{}

\begin{tabular}{ll}
Output:     & row vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the sums of the columns of \textsl{X}.
	  See also \hyperlink{func-meanc}{meanc}, \hyperlink{func-sumr}{sumr}.

\subsection{sumr}
\hypertarget{func-sumr}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Returns the sums of the rows of \textsl{X}.
	  See also \hyperlink{func-meanr}{meanr}, \hyperlink{func-sumc}{sumc}.

\subsection{svd}
\hypertarget{func-svd}{}

\begin{tabular}{ll}
Output:     & row vector\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{\&U} (reference to matrix, or \texttt{null})\\
           & \textsl{\&V} (reference to matrix, or \texttt{null})\\
\end{tabular}

	  Performs the singular values decomposition of the $r \times c$
	  matrix $X$: 
	  \[ X = U \left[
	  \begin{array}{cccc} 
	  \sigma_1 \\ 
	  & \sigma_2 \\ 
	  & & \ddots \\ 
	  & & & \sigma_n ,
	  \end{array}
	  \right] V \] 
	  where $n = \min(r,c)$. $U$ is $r \times
	  n$ and $V$ is $n \times c$, with $U'U = I$ and $VV' = I$.

	  The singular values are returned in a row vector.  The left
	  and/or right singular vectors \ensuremath{U} and \ensuremath{V}
	  may be obtained by supplying non-null values for arguments 2 and
	  3, respectively.  For any matrix \texttt{A}, the code

\begin{code}
	  s = svd(A, &U, &V) 
	  B = (U .* s) * V

\end{code}

	  should yield \texttt{B} identical to \texttt{A} (apart from
	  machine precision).

	  See also \hyperlink{func-eigengen}{eigengen}, \hyperlink{func-eigensym}{eigensym}, \hyperlink{func-qrdecomp}{qrdecomp}.

\subsection{tan}
\hypertarget{func-tan}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar, series or matrix)\\
\end{tabular}

	  Tangent.

\subsection{tr}
\hypertarget{func-tr}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{A} (square matrix)\\
\end{tabular}

	  Returns the trace of the square matrix \textsl{A},
	  namely $\sum_i A_{ii}$.
	  See also \hyperlink{func-diag}{diag}.

\subsection{transp}
\hypertarget{func-transp}{}

\begin{tabular}{ll}
Output:     & matrix\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  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: \texttt{X'}.

\subsection{trimr}
\hypertarget{func-trimr}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{X} (matrix)\\
           & \textsl{ttop} (scalar)\\
           & \textsl{tbot} (scalar)\\
\end{tabular}

	  Returns a matrix that is a copy of \textsl{X} with
	  \textsl{ttop} rows trimmed at the top and
	  \textsl{tbot} rows trimmed at the bottom.  The latter two
	  arguments must be non-negative, and must sum to less than the total
	  rows of \textsl{X}.

	  See also \hyperlink{func-selifr}{selifr}.

\subsection{uniform}
\hypertarget{func-uniform}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{a} (scalar)\\
           & \textsl{b} (scalar)\\
\end{tabular}

	  Generates a series of uniform pseudo-random variates in the
	  interval (\textsl{a}, \textsl{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 \hyperlink{func-randgen}{randgen}, \hyperlink{func-normal}{normal}, \hyperlink{func-genpois}{genpois}, \hyperlink{func-mnormal}{mnormal}, \hyperlink{func-muniform}{muniform}.

\subsection{unvech}
\hypertarget{func-unvech}{}

\begin{tabular}{ll}
Output:     & square matrix\\
Arguments:  & \textsl{v} (vector)\\
           & \textsl{b} (scalar)\\
\end{tabular}

	  Returns an \ensuremath{n\times n} symmetric matrix obtained by
	  rearranging the elements of \ensuremath{v}. The number of elements
	  in \ensuremath{v} must be a triangular integer --- i.e.{}, a
	  number \ensuremath{k} such that an integer \ensuremath{n} exists
	  with the property $k = n(n+1)/2$. This is the inverse of the function
	  \hyperlink{func-vech}{vech}. 

	  See also \hyperlink{func-mshape}{mshape}.

\subsection{upper}
\hypertarget{func-upper}{}

\begin{tabular}{ll}
Output:     & square matrix\\
Argument:   & \textsl{A} (square matrix)\\
\end{tabular}

	  Returns an $n\times n$ upper triangular matrix \ensuremath{B}
	  for which $B_{ij} = A_{ij}$ if $i \le j$ and 0 otherwise.

	  See also \hyperlink{func-lower}{lower}.

\subsection{values}
\hypertarget{func-values}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{x} (series or vector)\\
\end{tabular}

	  Returns a vector containing the distinct elements of
	  \textsl{x} sorted in ascending order.  If you wish to
	  truncate the values to integers before applying this function,
	  use the expression \texttt{values(int(x))}.

	  See also \hyperlink{func-dsort}{dsort}, \hyperlink{func-sort}{sort}.

\subsection{var}
\hypertarget{func-var}{}

\begin{tabular}{ll}
Output:     & scalar or series\\
Argument:   & \textsl{x} (series or list)\\
\end{tabular}

	  If \textsl{x} is a series, returns the (scalar) sample
	  variance, skipping any missing observations.

	  If \textsl{x} is a list, returns a series \ensuremath{y}
	  such that \ensuremath{y}\ensuremath{_{t}} is the sample variance of the
	  values of the variables in the list at observation \ensuremath{t},
	  or \texttt{NA} if there are any missing values at \ensuremath{t}.

	  In each case the sum of squared deviations from the mean is divided
	  by (\ensuremath{n} $-$ 1) for \ensuremath{n} > 1. Otherwise
	  the variance is given as zero if \ensuremath{n} = 1, or as
	  \texttt{NA} if \ensuremath{n} = 0.

	  See also \hyperlink{func-sd}{sd}.

\subsection{varname}
\hypertarget{func-varname}{}

\begin{tabular}{ll}
Output:     & string\\
Argument:   & \textsl{i} (scalar)\\
\end{tabular}

	  Returns the name of the variable with ID number
	  \textsl{i}, or generates an error if there is no such
	  variable.

\subsection{varnum}
\hypertarget{func-varnum}{}

\begin{tabular}{ll}
Output:     & scalar\\
Argument:   & \textsl{varname} (string)\\
\end{tabular}

	  Returns the ID number of the variable called
	  \textsl{varname}, or NA is there is no such variable.

\subsection{vec}
\hypertarget{func-vec}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{X} (matrix)\\
\end{tabular}

	  Stacks the columns of \textsl{X} as a column vector.
	  See also \hyperlink{func-mshape}{mshape}, \hyperlink{func-unvech}{unvech}, \hyperlink{func-vech}{vech}.

\subsection{vech}
\hypertarget{func-vech}{}

\begin{tabular}{ll}
Output:     & column vector\\
Argument:   & \textsl{A} (square matrix)\\
\end{tabular}

	  Returns in a column vector the elements of \textsl{A}
	  on and above the diagonal. Typically, this function is used on
	  symmetric matrices; in this case, it can be undone by the
	  function \hyperlink{func-unvech}{unvech}. 
	  See also \hyperlink{func-vec}{vec}.

\subsection{wmean}
\hypertarget{func-wmean}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{Y} (list)\\
           & \textsl{W} (list)\\
\end{tabular}

	  Returns a series \ensuremath{y} such that \ensuremath{y}\ensuremath{_{t}}
	  is the weighted mean of the values of the variables in list
	  \textsl{Y} at observation \ensuremath{t}, the respective
	  weights given by the values of the variables in list
	  \textsl{W} at \ensuremath{t}.  The weights can therefore
	  be time-varying. The lists \textsl{Y} and
	  \textsl{W} must be of the same length and the weights must
	  be non-negative.

	  See also \hyperlink{func-wsd}{wsd}, \hyperlink{func-wvar}{wvar}.

\subsection{wsd}
\hypertarget{func-wsd}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{Y} (list)\\
           & \textsl{W} (list)\\
\end{tabular}

	  Returns a series \ensuremath{y} such that \ensuremath{y}\ensuremath{_{t}}
	  is the weighted sample standard deviation of the values of the
	  variables in list \textsl{Y} at observation
	  \ensuremath{t}, the respective weights given by the values of the
	  variables in list \textsl{W} at \ensuremath{t}.  The
	  weights can therefore be time-varying. The lists
	  \textsl{Y} and \textsl{W} must be of the same
	  length and the weights must be non-negative.

	  See also \hyperlink{func-wmean}{wmean}, \hyperlink{func-wvar}{wvar}.

\subsection{wvar}
\hypertarget{func-wvar}{}

\begin{tabular}{ll}
Output:     & series\\
Arguments:  & \textsl{X} (list)\\
           & \textsl{W} (list)\\
\end{tabular}

	  Returns a series \ensuremath{y} such that \ensuremath{y}\ensuremath{_{t}}
	  is the weighted sample variance of the values of the
	  variables in list \textsl{X} at observation
	  \ensuremath{t}, the respective weights given by the values of the
	  variables in list \textsl{W} at \ensuremath{t}.  The
	  weights can therefore be time-varying. The lists
	  \textsl{Y} and \textsl{W} must be of the same
	  length and the weights must be non-negative.

	  The weighted sample variance is computed as
	  \[ s^2_w = \frac{n'}{n'-1} \,
	  \frac{\sum_{i=1}^n w_i(x_i - \bar{x}_w)^2}{\sum_{i=1}^n w_i} \]
	  where $n'$ is the number of non-zero weights and $\bar{x}_w$ is
	  the weighted mean.

	  See also \hyperlink{func-wmean}{wmean}, \hyperlink{func-wsd}{wsd}.

\subsection{xpx}
\hypertarget{func-xpx}{}

\begin{tabular}{ll}
Output:     & list\\
Argument:   & \textsl{L} (list)\\
\end{tabular}

	  Returns a list that references the squares and cross-products
	  of the variables in list \textsl{L}.  Squares are
	  named on the pattern \verb@sq_@\textsl{varname} and
	  cross-products on the pattern 
	  \textsl{var1}\verb@_@\textsl{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.

\subsection{zeromiss}
\hypertarget{func-zeromiss}{}

\begin{tabular}{ll}
Output:     & same type as input\\
Argument:   & \textsl{x} (scalar or series)\\
\end{tabular}

	  Converts zeros to \texttt{NA}s. If \textsl{x} is a
	  series, the conversion is done element by element.
	  See also \hyperlink{func-missing}{missing}, \hyperlink{func-misszero}{misszero}, \hyperlink{func-ok}{ok}.

\subsection{zeros}
\hypertarget{func-zeros}{}

\begin{tabular}{ll}
Output:     & matrix\\
Arguments:  & \textsl{r} (scalar)\\
           & \textsl{c} (scalar)\\
\end{tabular}

	  Outputs a zero matrix with \ensuremath{r} rows and
	  \ensuremath{c} columns. 
	  See also \hyperlink{func-ones}{ones}, \hyperlink{func-seq}{seq}.

