The EXPAND Procedure

Transformation Operations

The operations that can be used in the TRANSFORMIN= and TRANSFORMOUT= options are shown in Table 15.1. Operations are applied to each value of the series. Each value of the series is replaced by the result of the operation.

In Table 15.1, ${x_{t}}$ or x represents the value of the series at a particular time period t before the transformation is applied, ${y_{t}}$ represents the value of the result series, and N represents the total number of observations.

The notation $n_\mathrm {optional}$ indicates that the argument $n_\mathrm {optional}$ is an optional integer; the default is 1. The notation window is used as the argument for the moving statistics operators, and it indicates that you can specify either a number of periods n (where n is an integer) or a list of n weights in parentheses. The internal maximum value of the number of periods n is clipped at the number of observations in the series. The notation sequence is used as the argument for the sequence operators, and it indicates that you must specify a sequence of numbers. The notation s indicates the length of seasonality, and it is a required argument.

Table 15.1: Transformation Operations

Syntax

Result

+ number

Adds the specified number : ${x+\mathit{number}}$

$-$ number

Subtracts the specified number : ${x-\mathit{number}}$

* number

Multiplies by the specified number : ${x*\mathit{number}}$

/ number

Divides by the specified number : ${x / \mathit{number}}$

ABS

Absolute value: ${|x|}$

ADJUST

Indicates that the following moving window summation or product operator should be adjusted for window width

CD_I s

Classical decomposition irregular component

CD_S s

Classical decomposition seasonal component

CD_SA s

Classical decomposition seasonally adjusted series

CD_TC s

Classical decomposition trend-cycle component

CDA_I s

Classical decomposition (additive) irregular component

CDA_S s

Classical decomposition (additive) seasonal component

CDA_SA s

Classical decomposition (additive) seasonally adjusted series

CEIL

Smallest integer greater than or equal to x : ${\mr {ceil}(x)}$

CMOVAVE window

Centered moving average

CMOVCSS window

Centered moving corrected sum of squares

CMOVGMEAN window

Centered moving geometric mean

 

for window = number of periods, $n$:

 

$(\prod _{j=j_\mathrm {min}}^{j_\mathrm {max}}x_{t+j})^{1/n}$

 

$j_\mathrm {min}=-(n+n\mod 2)/2 + 1$

 

$j_\mathrm {max}=(n-n\mod 2)/2$

 

for window = weight list, $w$:

 

$(\prod _{j=j_\mathrm {min}}^{j_\mathrm {max}}x_{t+j}^{w_{j-j_\mathrm {min}}}) ^{1/\sum _{j=0}^{n-1}w_ j}$

CMOVMAX n

Centered moving maximum

CMOVMED n

Centered moving median

CMOVMIN n

Centered moving minimum

CMOVPROD window

Centered moving product

 

for window = number of periods, $n$:

 

$\prod _{j=j_\mathrm {min}}^{j_\mathrm {max}}x_{t+j}$

 

for window = weight list, $w$:

 

$(\prod _{j=j_\mathrm {min}}^{j_\mathrm {max}}x_{t+j}^{w_{j-j_\mathrm {min}}}) ^{1/\sum _{j=0}^{n-1}w_ j}$

CMOVRANGE n

Centered moving range

CMOVRANK $n$

Centered moving rank

CMOVSTD window

Centered moving standard deviation

CMOVSUM n

Centered moving sum

CMOVTVALUE window

Centered moving t value

CMOVUSS window

Centered moving uncorrected sum of squares

CMOVVAR window

Centered moving variance

CUAVE $n_\mathrm {optional}$

Cumulative average

CUCSS $n_\mathrm {optional}$

Cumulative corrected sum of squares

CUGMEAN $n_\mathrm {optional}$

Cumulative geometric mean

CUMAX $n_\mathrm {optional}$

Cumulative maximum

CUMED $n_\mathrm {optional}$

Cumulative median

CUMIN $n_\mathrm {optional}$

Cumulative minimum

CUPROD $n_\mathrm {optional}$

Cumulative product

CURANK $n_\mathrm {optional}$

Cumulative rank

CURANGE $n_\mathrm {optional}$

Cumulative range

CUSTD $n_\mathrm {optional}$

Cumulative standard deviation

CUSUM $n_\mathrm {optional}$

Cumulative sum

CUTVALUE $n_\mathrm {optional}$

Cumulative t value

CUUSS $n_\mathrm {optional}$

Cumulative uncorrected sum of squares

CUVAR $n_\mathrm {optional}$

Cumulative variance

DIF $n_\mathrm {optional}$

Span n difference: ${x_{t}-x_{t-n}}$

EWMA number

Exponentially weighted moving average of ${x}$ with

 

smoothing weight number, where ${0 < number < 1}$:

 

${y_{t} = number~ ~  x_{t} + (1-number) y_{t-1}}$.

 

This operation is also called simple exponential smoothing.

EXP

Exponential function: ${\exp (x)}$

FDIF d

Fractional difference with difference order $d$ where $0 < d < 0.5$

FLOOR

Largest integer less than or equal to x : ${\mr {floor}(x)}$

FSUM $d$

Fractional summation with summation order $d$ where $0 < d < 0.5$

HP_T lambda

Hodrick-Prescott Filter trend component where lambda is the nonnegative filter parameter

HP_C lambda

Hodrick-Prescott Filter cycle component where lambda is the nonnegative filter parameter

ILOGIT

Inverse logistic function: ${\frac{\exp (x)}{1+\exp (x)}}$

LAG $n_\mathrm {optional}$

Value of the series n periods earlier: ${x_{t-n}}$

LEAD $n_\mathrm {optional}$

Value of the series n periods later: ${x_{t+n}}$

LOG

Natural logarithm: ${\log (x)}$

LOGIT

Logistic function: ${{\log }(\frac{x}{1-x})}$

MAX number

Maximum of x and number : ${\max (x,\textit{number})}$

MIN number

Minimum of x and number : ${\min (x,\textit{number})}$

> number

Missing value if ${x <= \textit{number}}$, else x

>= number

Missing value if ${x < \textit{number}}$, else x

= number

Missing value if ${x ~ {\ne }~  \textit{number}}$, else x

$\wedge $= number

Missing value if ${x = \textit{number}}$, else x

< number

Missing value if ${x >= \textit{number}}$, else x

<= number

Missing value if ${x > \textit{number}}$, else x

MOVAVE n

Backward moving average of n neighboring values:

 

${\frac{1}{n} \sum _{j=0}^{n-1}{x_{t-j}}}$

MOVAVE window

Backward weighted moving average of neighboring values:

 

${{(\sum _{j=1}^{n}{w_{j}x_{t-n+j})}}/{(\sum _{j=1}^{n}{w_{j}})}}$

MOVCSS window

Backward moving corrected sum of squares

MOVGMEAN window

Backward moving geometric mean

 

for window = number of periods, $n$:

 

$(\prod _{j=1}^{n}x_{t-n+j})^{1/n}$

 

for window = weight list, $w$:

 

$(\prod _{j=1}^{n}x_{t-n+j}^{w_ j}) ^{1/\sum _{j=1}^{n}w_ j}$

MOVMAX n

Backward moving maximum

MOVMED n

Backward moving median

MOVMIN n

Backward moving minimum

MOVPROD window

Backward moving product

 

for window = number of periods, $n$:

 

$\prod _{j=1}^{n}x_{t-n+j}$

 

for window = weight list, $w$:

 

$(\prod _{j=1}^{n}x_{t-n+j}^{w_ j}) ^{1/\sum _{j=1}^{n}w_ j}$

MOVRANGE n

Backward moving range

MOVRANK $n$

Backward moving rank

MOVSTD window

Backward moving weighted standard deviation:

 

${\sqrt {{\frac{1}{n-1}\sum _{j=1}^{n}w_ i(x_{j}-\overline{x}_{w})^2}}}$

MOVSUM n

Backward moving sum

MOVTVALUE window

Backward moving t value

MOVUSS window

Backward moving uncorrected sum of squares

MOVVAR window

Backward moving variance

MISSONLY <MEAN>

Indicates that the following moving time window

 

statistic operator should replace only missing values with the

 

moving statistic and should leave nonmissing values unchanged.

 

If the option MEAN is specified, then missing values are

 

replaced by the overall mean of the series.

NEG

Changes the sign: ${-x}$

NOMISS

Indicates that the following moving time window

 

statistic operator should not allow missing values

PCTDIF $n$

Percent difference of the current value and lag $n$

PCTSUM $n$

Percent summation of the current value and cumulative sum $n$-lag periods

RATIO $n$

Ratio of current value to lag $n$

RECIPROCAL

Reciprocal: ${{1}/{x}}$

REVERSE

Reverses the series: ${x_{_{N-t}}}$

SCALE $n_1$ $n_2$

Scales the series between $n_1$ and $n_2$

SEQADD sequence

Adds sequence values to series

SEQDIV sequence

Divides the series by sequence values

SEQMINUS sequence

Subtracts sequence values to series

SEQMULT sequence

Multiplies the series by sequence values

SET ($n_1$ $n_2$)

Sets all values of $n_1$ to $n_2$

SETEMBEDDED ($n_1$ $n_2$)

Sets embedded values of $n_1$ to $n_2$

SETLEFT ($n_1$ $n_2$)

Sets beginning values of $n_1$ to $n_2$

SETMISS number

Replaces missing values in the series with the number specified

SETRIGHT ($n_1$ $n_2$)

Sets ending values of $n_1$ to $n_2$

SIGN

$-1$, 0, or 1 as x is < 0, equals 0, or > 0, respectively

SQRT

Square root: ${\sqrt {x}}$

SQUARE

Square: ${x^{2}}$

SUM

Cumulative sum: ${\sum _{j=1}^{t}{x_{j}}}$

SUM n

Cumulative sum of multiples of n-period lags:

 

${x_{t}+x_{t-n}+x_{t-2n}+\ldots }$

TRIM n

Sets ${x_{t}}$ to missing a value if ${t {\le } n}$ or ${t {\ge } N-n+1}$

TRIMLEFT n

Sets ${x_{t}}$ to missing a value if ${t {\le } n}$

TRIMRIGHT n

Sets ${x_{t}}$ to missing a value if ${t {\ge } N-n+1}$


Moving Time Window Operators

Some operators compute statistics for a set of values within a moving time window; these are called moving time window operators. There are centered and backward versions of these operators.

The centered moving time window operators are CMOVAVE, CMOVCSS, CMOVGMEAN, CMOVMAX, CMOVMED, CMOVMIN, CMOVPROD, CMOVRANGE, CMOVRANK, CMOVSTD, CMOVSUM, CMOVTVALUE, CMOVUSS, and CMOVVAR. These operators compute statistics of the ${n}$ values ${x_{i}}$ for observations $t -(n+n\mod 2)/2 + 1 \le i \le t + (n-n\mod 2)/2$

The backward moving time window operators are MOVAVE, MOVCSS, MOVGMEAN, MOVMAX, MOVMED, MOVMIN, MOVPROD, MOVRANGE, MOVRANK, MOVSTD, MOVSUM, MOVTVALUE, MOVUSS, and MOVVAR. These operators compute statistics of the ${n}$ values ${x_{t}, x_{t-1}, {\ldots }, x_{t-n+1}}$.

All the moving time window operators accept an argument ${n}$ specifying the number of periods to include in the time window. For example, the following statement computes a five-period backward moving average of X.

   convert x=y / transformout=( movave 5 );

In this example, the resulting transformation is

\[  y_{t} = (x_{t} + x_{t-1} + x_{t-2} + x_{t-3} + x_{t-4}) / 5  \]

The following statement computes a five-period centered moving average of X.

   convert x=y / transformout=( cmovave 5 );

In this example, the resulting transformation is

\[  y_{t} = (x_{t-2} + x_{t-1} + x_{t} + x_{t+1} + x_{t+2})/5  \]

If the window with a centered moving time window operator is not an odd number, one more lead value than lag value is included in the time window. For example, the result of the CMOVAVE 4 operator is

\[  y_{t} = (x_{t-1} + x_{t} + x_{t+1} + x_{t+2})/4  \]

You can compute a forward moving time window operation by combining a backward moving time window operator with the REVERSE operator. For example, the following statement computes a five-period forward moving average of X.

   convert x=y / transformout=( reverse movave 5 reverse );

In this example, the resulting transformation is

\[  y_{t} = (x_{t} + x_{t+1} + x_{t+2} + x_{t+3} + x_{t+4})/5  \]

Some of the moving time window operators enable you to specify a list of weight values to compute weighted statistics. These are CMOVAVE, CMOVCSS, CMOVGMEAN, CMOVPROD, CMOVSTD, CMOVTVALUE, CMOVUSS, CMOVVAR, MOVAVE, MOVCSS, MOVGMEAN, MOVPROD, MOVSTD, MOVTVALUE, MOVUSS, and MOVVAR.

To specify a weighted moving time window operator, enter the weight values in parentheses after the operator name. The window width ${n}$ is equal to the number of weights that you specify; do not specify ${n}$.

For example, the following statement computes a weighted five-period centered moving average of X.

   convert x=y / transformout=( cmovave( .1 .2 .4 .2 .1 ) );

In this example, the resulting transformation is

\[  y_{t} = .1 x_{t-2} + .2 x_{t-1} + .4 x_{t} + .2 x_{t+1} + .1 x_{t+2}  \]

The weight values must be greater than zero. If the weights do not sum to 1, the weights specified are divided by their sum to produce the weights used to compute the statistic.

A complete time window is not available at the beginning of the series. For the centered operators a complete window is also not available at the end of the series. The computation of the moving time window operators is adjusted for these boundary conditions as follows.

For backward moving window operators, the width of the time window is shortened at the beginning of the series. For example, the results of the MOVSUM 3 operator are

\begin{eqnarray*}  y_{1} & =&  x_{1} \\ y_{2} & =&  x_{1} + x_{2} \\ y_{3} & =&  x_{1} + x_{2} + x_{3} \\ y_{4} & =&  x_{2} + x_{3} + x_{4} \\ y_{5} & =&  x_{3} + x_{4} + x_{5} \\ & \cdots & \end{eqnarray*}

For centered moving window operators, the width of the time window is shortened at the beginning and the end of the series due to unavailable observations. For example, the results of the CMOVSUM 5 operator are

\begin{eqnarray*}  y_{1} & =&  x_{1} + x_{2} + x_{3} \\ y_{2} & =&  x_{1} + x_{2} + x_{3} + x_{4} \\ y_{3} & =&  x_{1} + x_{2} + x_{3} + x_{4} + x_{5} \\ y_{4} & =&  x_{2} + x_{3} + x_{4} + x_{5} + x_{6} \\ & \cdots & \\ y_{_{N-2}} & =&  x_{_{N-4}} + x_{_{N-3}} + x_{_{N-2}} + x_{_{N-1}} + x_{_{N}} \\ y_{_{N-1}} & =&  x_{_{N-3}} + x_{_{N-2}} + x_{_{N-1}} + x_{_{N}} \\ y_{_{N}} & =&  x_{_{N-2}} + x_{_{N-1}} + x_{_{N}} \end{eqnarray*}

For weighted moving time window operators, the weights for the unavailable or unused observations are ignored and the remaining weights renormalized to sum to 1.

Cumulative Statistics Operators

Some operators compute cumulative statistics for a set of current and previous values of the series. The cumulative statistics operators are CUAVE, CUCSS, CUMAX, CUMED, CUMIN, CURANGE, CUSTD, CUSUM, CUUSS, and CUVAR.

By default, the cumulative statistics operators compute the statistics from all previous values of the series, so that ${y_{t}}$ is based on the set of values ${x_{t}, x_{t-1}, \ldots , x_{1}}$. For example, the following statement computes ${y_{t}}$ as the cumulative sum of nonmissing ${x_{i}}$ values for ${i {\le } t}$.

   convert x=y / transformout=( cusum );

You can specify a lag increment argument $n$ for the cumulative statistics operators. In this case, the statistic is computed from the current and every $n^{th}$ previous value. When $n$ is specified these operators compute statistics of the values ${x_{t}, x_{t-n}, x_{t-2n}, {\ldots }, x_{t-in}}$ for ${t-in > 0}$.

For example, the following statement computes ${y_{t}}$ as the cumulative sum of nonmissing ${x_{i}}$ values for odd ${i}$ when ${t}$ is odd and for even ${i}$ when ${t}$ is even.

   convert x=y / transformout=( cusum 2 );

The results of this example are

\begin{eqnarray*}  y_{1} & =&  x_{1} \\ y_{2} & =&  x_{2} \\ y_{3} & =&  x_{1} + x_{3} \\ y_{4} & =&  x_{2} + x_{4} \\ y_{5} & =&  x_{1} + x_{3} + x_{5} \\ y_{6} & =&  x_{2} + x_{4} + x_{6} \\ & \cdots & \end{eqnarray*}

Missing Values

You can truncate the length of the result series by using the TRIM, TRIMLEFT, and TRIMRIGHT operators to set values to missing at the beginning or end of the series.

You can use these functions to trim the results of moving time window operators so that the result series contains only values computed from a full width time window. For example, the following statements compute a centered five-period moving average of X, and they set to missing values at the ends of the series that are averages of fewer than five values.

   convert x=y / transformout=( cmovave 5 trim 2 );

Normally, the moving time window and cumulative statistics operators ignore missing values and compute their results for the nonmissing values. When preceded by the NOMISS operator, these functions produce a missing result if any value within the time window is missing.

The NOMISS operator does not perform any calculations, but serves to modify the operation of the moving time window operator that follows it. The NOMISS operator has no effect unless it is followed by a moving time window operator.

For example, the following statement computes a five-period moving average of the variable X but produces a missing value when any of the five values are missing.

   convert x=y / transformout=( nomiss movave 5 );

The following statement computes the cumulative sum of the variable X but produces a missing value for all periods after the first missing X value.

   convert x=y / transformout=( nomiss cusum );

Similar to the NOMISS operator, the MISSONLY operator does not perform any calculations (unless followed by the MEAN option), but it serves to modify the operation of the moving time window operator that follows it. When preceded by the MISSONLY operator, these moving time window operators replace any missing values with the moving statistic and leave nonmissing values unchanged.

For example, the following statement replaces any missing values of the variable X with an exponentially weighted moving average of the past values of X and leaves nonmissing values unchanged. The missing values are interpolated using the specified exponentially weighted moving average. (This is also called simple exponential smoothing.)

   convert x=y / transformout=( missonly ewma 0.3 );

The following statement replaces any missing values of the variable X with the overall mean of X.

   convert x=y / transformout=( missonly mean );

You can use the SETMISS operator to replace missing values with a specified number. For example, the following statement replaces any missing values of the variable X with the number 8.77.

   convert x=y / transformout=( setmiss 8.77 );

Classical Decomposition Operators

If ${x_{t}}$ is a seasonal time series with $s$ observations per season, classical decomposition methods break down the time series into four components: trend, cycle, seasonal, and irregular components. The trend and cycle components are often combined to form the trend-cycle component. There are two basic forms of classical decomposition: multiplicative and additive, which are show below.

\begin{eqnarray*}  x_{t} & =&  TC_{t}S_{t}I_{t} \\ x_{t} & =&  TC_{t} + S_{t} + I_{t} \end{eqnarray*}

where

${TC_{t}}$

is the trend-cycle component

${S_{t} }$

is the seasonal component or seasonal factors that are periodic with period $s$ and with mean one (multiplicative) or zero (additive)

${I_{t} }$

is the irregular or random component that is assumed to have mean one (multiplicative) or zero (additive)

For multiplicative decomposition, all of the $x_ t$ values should be positive.

The CD_TC operator computes the trend-cycle component for both the multiplicative and additive models. When ${s}$ is odd, this operator computes an ${s}$-period centered moving average as follows:

\[  TC_{t} = \sum _{k=-{\lfloor s/2 \rfloor }}^{{\lfloor s/2 \rfloor }}{x_{t+k}/s}  \]

For example, in the case where s=5, the CD_TC s operator

   convert x=tc / transformout=( cd_tc 5 );

is equivalent to the following CMOVAVE operator:

   convert x=tc / transformout=( cmovave 5 trim 2 );

When ${s}$ is even, the CD_TC s operator computes the average of two adjacent ${s}$-period centered moving averages as follows:

\[  TC_{t} = \sum _{k = -{\lfloor s/2 \rfloor }}^{{\lfloor s/2 \rfloor }-1}{(x_{t+k}+x_{t+1+k})/2s}  \]

For example, in the case where s=12, the CD_TC s operator

   convert x=tc / transformout=( cd_tc 12 );

is equivalent to the following CMOVAVE operator:

   convert x=tc / transformout=(cmovave 12 movave 2 trim 6);

The CD_S and CDA_S operators compute the seasonal components for the multiplicative and additive models, respectively. First, the trend-cycle component is computed as shown previously. Second, the seasonal-irregular component is computed by ${SI_{t} = x_{t}/TC_{t} }$ for the multiplicative model and by ${SI_{t} = x_{t}-TC_{t} }$ for the additive model. The seasonal component is obtained by averaging the seasonal-irregular component for each season.

\[  S_{k+js} = \sum _{t = k \bmod s}\frac{SI_ t}{n/s}  \]

where ${0 {\le } j {\le } n/s }$ and ${1 {\le } k {\le } s }$. The seasonal components are normalized to sum to one (multiplicative) or zero (additive).

The CD_I and CDA_I operators compute the irregular component for the multiplicative and additive models respectively. First, the seasonal component is computed as shown previously. Next, the irregular component is determined from the seasonal-irregular and seasonal components as appropriate.

\begin{eqnarray*}  I_{t} & =&  SI_{t}/S_{t} \\ I_{t} & =&  SI_{t}-S_{t} \end{eqnarray*}

The CD_SA and CDA_SA operators compute the seasonally adjusted time series for the multiplicative and additive models, respectively. After decomposition, the original time series can be seasonally adjusted as appropriate.

\begin{eqnarray*}  \tilde x_{t} & =&  x_{t}/S_{t} = TC_{t}I_{t} \\ \tilde x_{t} & =&  x_{t} - S_{t} = TC_{t} + I_{t} \end{eqnarray*}

The following statements compute all the multiplicative classical decomposition components for the variable X for $s$=12.

   convert x=tc / transformout=( cd_tc 12 );
   convert x=s  / transformout=( cd_s  12 );
   convert x=i  / transformout=( cd_i  12 );
   convert x=sa / transformout=( cd_sa 12 );

The following statements compute all the additive classical decomposition components for the variable X for $s$=4.

   convert x=tc / transformout=( cd_tc  4 );
   convert x=s  / transformout=( cda_s  4 );
   convert x=i  / transformout=( cda_i  4 );
   convert x=sa / transformout=( cda_sa 4 );

The X12 and X11 procedures provides other methods for seasonal decomposition. See Chapter 37: The X12 Procedure, and Chapter 36: The X11 Procedure.

Fractional Operators

For fractional operators, the parameter, d, represents the order of fractional differencing. Fractional summation is the inverse operation of fractional differencing.

Examples of Usage

Suppose that X is a fractionally integrated time series variable of order d=0.25. Fractionally differencing X forms a time series variable Y which is not integrated.

   convert x=y / transformout=(fdif 0.25);

Suppose that Z is a non-integrated time series variable. Fractionally summing Z forms a time series W which is fractionally integrated of order $d=0.25$.

   convert z=w / transformout=(fsum 0.25);

Moving Rank Operators

For the rank operators, the ranks are computed based on the current value with respect to the cumulative, centered, or moving window values. If the current value is missing, the transformed current value is set to missing. If the NOMISS option was previously specified and if any missing values are present in the moving window, the transformed current value is set to missing. Otherwise, redundant values from the moving window are removed and the rank of the current value is computed among the unique values of the moving window.

Examples of Usage

The trades of a particular security are recorded for each weekday in a variable named PRICE. Given the historical daily trades, the ranking of the price of this security for each trading day, considering its entire past history, can be computed as follows:

   convert price=history / transformout=( curank );

The ranking of the price of this security for each trading day considering the previous week’s history can be computed as follows:

   convert price=lastweek / transformout=( movrank 5 );

The ranking of the price of this security for each trading day considering the previous two week’s history can be computed as follows:

   convert price=twoweek / transformout=( movrank 10 );

Moving Product and Geometric Mean Operators

For the product and geometric mean operators, the current transformed value is computed based on the (weighted) product of the cumulative, centered, or moving window values. If missing values are present in the moving window and the NOMISS operator is previously specified, the current transformed value is set to missing. Otherwise, the current transformed value is set to the product of the nonmissing values within the moving window. If a geometric mean operator is specified for a window of size $n$, the $n\mathrm{th}$ root of the product is taken. In cases where weights are specified explicitly, both the product and geometric mean operators normalize these exponents so that they sum to one.

Examples of Usage

The interest rates for a savings account are recorded for each month in the data set variable RATES. The cumulative interest rate for each month considering the entire account past history can be computed as follows:

   convert rates=history / transformout=( + 1 cuprod - 1);

The interest rate for each quarter considering the previous quarter’s history can be computed as follows:

   convert rates=lastqtr / transformout=( + 1 movprod 3 - 1);

The average interest rate for the previous quarter’s history can be computed as follows:

   convert rates=lastqtr / transformout=( + 1 movprod (1 1 1) - 1);

Sequence Operators

For the sequence operators, the sequence values are used to compute the transformed values from the original values in a sequential fashion. You can add to or subtract from the original series or you can multiply or divide by the sequence values. The first sequence value is applied to the first observation of the series, the second sequence value is applied to the second observation of the series, and so on until the end of the sequence is reached. At this point, the first sequence value is applied to the next observation of the series and the second sequence value on the next observation and so on.

Let $v_1, \ldots , v_ m$ be the sequence values and let $x_ t$, $t=1,\ldots N$, be the original time series. The transformed series, $y_ t$, is computed as follows:

\begin{eqnarray*}  y_1 & =&  x_1 \  op \   v_1 \\ y_2 & =&  x_2 \  op \  v_2 \\ & \cdots & \\ y_ m & =&  x_ m \  op \  v_ m \\ y_{m+1} & =&  x_{m+1} \  op \  v_1 \\ y_{m+2} & =&  x_{m+2} \  op \  v_2 \\ & \cdots & \\ y_{2m} & =&  x_{2m} \  op \  v_ m \\ y_{2m+1} & =&  x_{2m+1} \  op \  v1 \\ y_{2m+2} & =&  x_{2m+2} \  op \  v2 \\ & \cdots & \end{eqnarray*}

where $op = +, - , *, \mr {\  or\  } /$.

Examples of Usage

The multiplicative seasonal indices are 0.9, 1.2. 0.8, and 1.1 for the four quarters. Let SEASADJ be a quarterly time series variable that has been seasonally adjusted in a multiplicative fashion. To restore the seasonality to SEASADJ use the following transformation:

   convert seasadj=seasonal /
           transformout=(seqmult (0.9 1.2 0.8 1.1));

The additive seasonal indices are 4.4, -1.1, -2.1, and -1.2 for the four quarters. Let SEASADJ be a quarterly time series variable that has been seasonally adjusted in additive fashion. To restore the seasonality to SEASADJ use the following transformation:

   convert seasadj=seasonal /
           transformout=(seqadd (4.4 -1.1 -2.1 -1.2));

Set Operators

For the set operators, the first parameter, $n_1$, represents the value to be replaced and the second parameter, $n_2$, represents the replacement value. The replacement can be localized to the beginning, middle, or end of the series.

Examples of Usage

Suppose that a store opened recently and that the sales history is stored in a database that does not recognize missing values. Even though demand may have existed prior to the stores opening, this database assigns the value of zero. Modeling the sales history may be problematic because the sales history is mostly zero. To compensate for this deficiency, the leading zero values should be set to missing with the remaining zero values unchanged (representing no demand).

   convert sales=demand / transformout=(setleft (0 .));

Likewise, suppose a store is closed recently. The demand might still be present; hence, a recorded value of zero does not accurately reflect actual demand.

   convert sales=demand / transformout=(setright (0 .));

Scale Operator

For the scale operator, the first parameter, $n_1$, represents the value associated with the minimum value ($x_{min}$) and the second parameter, $n_2$, represents the value associated with the maximum value ($x_{max}$) of the original series ($x_ t$). The scale operator rescales the original data to be between the parameters $n_1$ and $n_2$ as follows:

\[  y_ t = ((n_2 - n_1) / (x_{max} - x_{min}))( x_ t - x_{min}) + n_1  \]
Examples of Usage

Suppose that two new product sales histories are stored in variables $X$ and $Y$ and you wish to determine their adoption rates. In order to compare their adoption histories the variables must be scaled for comparison.

   convert x=w / transformout=(scale 0 1);
   convert y=z / transformout=(scale 0 1);

Adjust Operator

For the moving summation and product window operators, the window widths at the beginning and end of the series are smaller than those in the middle of the series. Likewise, if there are embedded missing values, the window width is smaller than specified. When preceded by the ADJUST operator, the moving summation (MOVSUM CMOVSUM) and moving product operators (MOVPROD CMOVPROD) are adjusted by the window width.

For example, suppose the variable $X$ has 10 values and the moving summation operator of width 3 is applied to $X$ to create the variable $Y$ with window width adjustment and the variable $Z$ without adjustment.

   convert x=y / transformout=(adjust movsum 3);
   convert x=z / transformout=(movsum 3);

The above transformations result in the following relationship between $Y$ and $Z$: $y_1 = 3z_1$, $y_2 = \frac{3}{2}z_2$, $y_ t = z_ t$ for $t > 2$ because the first two window widths are smaller than 3.

For example, suppose the variable $X$ has 10 values and the moving multiplicative operator of width 3 is applied to $X$ to create the variable $Y$ with window width adjustment and the variable $Z$ without adjustment.

   convert x=y / transformout=(adjust movprod 3);
   convert x=z / transformout=(movprod 3);

The above transformation result in the following: $y_1 = z_1^3$, $y_2 = z_2^{3/2}$, $y_ t = z_ t$ for $t > 2$ because the first two window widths are smaller than 3.

Moving T-Value Operators

The moving t-value operators (CUTVALUE, MOVTVALUE, CMOVTVALUE) compute the t-value of the cumulative series or moving window. They can be viewed as combinations of the moving average (CUAVE, MOVAVE, CMOVAVE) and the moving standard deviation (CUSTD, MOVSTD, CMOVSTD), respectively.

Percent Operators

The percentage operators compute the percent summation and the percent difference of the current value and the $\mr {lag} (n)$. The percent summation operator (PCTSUM) computes $y_ t = 100 x_ t/\mr {cusum} (x_{t-n})$. If any of the values of the preceding equation are missing or the cumulative summation is zero, the result is set to missing. The percent difference operator (PCTDIF) computes $y_ t = 100 (x_ t - x_{t-n})/x_{t-n}$. If any of the values of the preceding equation are missing or the lag value is zero, the result is set to missing.

For example, suppose variable $X$ contains the series. The percent summation of lag 4 is applied to $X$ to create the variable $Y$. The percent difference of lag 4 is applied to $X$ to create the variable $Z$.

   convert x=y / transformout=(pctsum 4);
   convert x=z / transformout=(pctdif 4);

Ratio Operators

The ratio operator computes the ratio of the current value and the $\mr {lag} (n)$ value. The ratio operator (RATIO) computes $y_ t = x_ t/x_{t-n}$. If any of the values of the preceding equation are missing or the lag value is zero, the result is set to missing.

For example, suppose variable $X$ contains the series. The ratio of the current value and the lag 4 value of $X$ assigned to the variable $Y$. The percent ratio of the current value and lag 4 value of $X$ is assigned to the variable $Z$.

   convert x=y / transformout=(ratio 4);
   convert x=z / transformout=(ratio 4 * 100);