SHAZAM Community
Ask Your Question

Revision history [back]

The answer to the question of generating row averages can be done simply using the stat command after computing A. Try:

* Compute Averages on entire matrix
* N.B. STAT on a matrix operates over columns so transpose first
matrix AT = A'
stat AT / means=rowmeans
graph rowmeans / nokey

Also it can be done the mechanical way using GENR to convert a vector to a data series as follows:

* Dimension the results vector
dim Averages length
do(# = 1, length)
  * Convert column of matrix to a vector
  matrix vector=vec(A(#,0))
  * Convert a vector to a data series
  genr dataVec=vector
  * Compute the mean for the single column
  stat dataVec / means = rowMean
  * Store mean to vector at position #
  matrix Averages(#) = rowMean
endo

And check the results are the same as follows:

* Check both are the same
print rowMeans Averages

The answer to the question of asked in the comment above regarding generating row averages can be done simply using the stat command after computing A. Try:

* Compute Averages on entire matrix
* N.B. STAT on a matrix operates over columns so transpose first
matrix AT = A'
stat AT / means=rowmeans
graph rowmeans / nokey

Also it can be done the mechanical way using GENR to convert a vector to a data series as follows:follows but note that process of converting to a data series is also not really required. The STAT command will work on a vector just the same as with a matrix. This is shown mainly to highlight some useful techniques:

* Dimension the results vector
dim Averages length

* Loop through the generated time steps
do(# = 1, length)
  * Convert column of matrix to a vector
  matrix vector=vec(A(#,0))
  * Convert a vector to a data series
  genr dataVec=vector
  * Compute the mean for the single column
  stat dataVec / means = rowMean
  * Store mean to vector at position #
  matrix Averages(#) = rowMean
endo

And check the results are the same as follows:

* Check both are the same
print rowMeans Averages

The answer to the question asked in the comment above regarding generating row averages can be done simply using the stat STAT command after computing A. Try:

* First transpose the A matrix so that we can use the STAT command, which treats columns as seperate series when used with a matrix: 

matrix AT = A'

Compute Averages on entire matrix * N.B. STAT on a matrix operates over columns so transpose first matrix AT = A' the means and store them in a variable called rowMeans:

stat AT / means=rowmeans
means=rowMeans

Graph as before using:

graph rowmeans rowMeans / nokey

Also it can be done the mechanical way using GENR to convert a vector to a data series as follows but note that process of converting to a data series is also not really required. The STAT command will work on a vector just the same as with a matrix. This is shown mainly to highlight some useful techniques:

* Dimension the results vector
dim Averages length

* Loop through the generated time steps
do(# = 1, length)
  * Convert column of matrix to a vector
  matrix vector=vec(A(#,0))
  * Convert a vector to a data series
  genr dataVec=vector
  * Compute the mean for the single column
  stat dataVec / means = rowMean
  * Store mean to vector at position #
  matrix Averages(#) = rowMean
endo

And check the results are the same as follows:

* Check both are the same
print rowMeans Averages

The answer to the question asked in the comment above regarding generating row averages can be done simply using the STAT command after computing A. First transpose the A matrix so that we can use the STAT command, which treats columns as seperate series when used with a matrix:

matrix AT = A'

Compute the means and store them in a variable called rowMeans:

stat AT / means=rowMeans

Graph as before using:

graph rowMeans / nokey

Also it can be done the mechanical way using GENR to convert a vector to a data series as follows but note that process of converting to a data series is also not really required. The STAT command will work on a vector just the same as with a matrix. This is shown mainly to highlight some useful techniques:

* Dimension the results vector
dim Averages length

* Loop through the generated time steps
do(# = 1, length)
  * Convert column row of matrix to a vector
  matrix vector=vec(A(#,0))
  * Convert a the vector to a data series
  genr dataVec=vector
dataSeries=vector
  * Compute the mean for the single column
data series (row)
  stat dataVec dataSeries / means = rowMean
  * Store mean to vector at position #
  matrix Averages(#) = rowMean
endo

And check the results are the same as follows:

* Check both are the same
print rowMeans Averages