Command Reference : Matrix Language Reference
  
 
@trendcoef
Syntax: @trendcoef(m)
m: vector, matrix
Return: number
Returns the trend coefficient of an OLS regression on matrix or vector m versus a constant and an implicit time trend, as in @detrend.
When applied to a matrix, the matrix elements are arranged in vectorization order and then paired with the implicit time trend.
Examples
We begin by creating a workfile, generating a random series, and then converting to a vector so that we can compute identical results using the series and the vector.
workfile u 100
series y = nrnd
vector yv = @convert(y)
The trend regression trend coefficient estimate is given by
scalar tr1 = @trendcoef(yv)
Alternately, the trend regression results may be obtained using the vector YV using the @regress command on the augmented data matrix:
matrix vcoefs = @regress(@hcat(yv, @ones(yv.@rows), @range(0, yv.@rows-1))
The first column of VCOEFS contains the intercept and trend coefficients, so
scalar tr2 = vcoefs(2)
is the trend coefficient.
Estimates may also be obtained using the series and an equation object
equation eq1.ls y c @trend
scalar icpt3 = eq1.c(2)
Cross-references
See also @intercept, @cintercept, and @ctrendcoef.