Clyde and statalist members: I'm getting invalid syntax r98 error when reading in a lower triangle .txt file of variances - covariances using Clyde's new code for 87 variables. I'm unable to spot where the error is and how it might be corrected.
cd c:\chest
c:\chest
. set more off
. clear
. import delimited c:\Mplus\oct292024montecarlovarcovmtx.txt
(1 var, 766 obs)
.
. // Clyde's revised Dec 6 2024 code follows
. split v1, gen(var) destring
variables born as string:
var1 var2 var3 var4 var5
var1 has all characters numeric; replaced as double
var2 has all characters numeric; replaced as double
var3 has all characters numeric; replaced as double
var4 has all characters numeric; replaced as double
(1 missing value generated)
var5 has all characters numeric; replaced as double
(1 missing value generated)
. drop v1
.
. // CREATE THE MATRIX
. local nvars 87 //Set nvars to the num of variables you have*/
. local r 1
. local c 1
.
. matrix M = I(`nvars')
.
. forvalues o = 1/`=_N' {
2. forvalues v = 1/`ncols' {
3. matrix M[`r', `c'] = var`v'[`o']
4. if `r' != `c' {
5. matrix M[`c', `r'] = M[`r', `c']
6. }
7. local ++c
8. if `c' > `r' {
9. local c = 1
10. if `r' < `nvars' {
11. local ++r
12. }
13. else {
14. continue, break
15. }
16. }
17. }
18. }
invalid syntax
r(198);
end of do-file
r(198);
Here is the complete do code I'm trying to run:
cd c:\chest
set more off
clear
import delimited c:\Mplus\oct292024montecarlovarcovmtx.txt
// Clyde's revised Dec 6 2024 code follows
split v1, gen(var) destring
drop v1
// CREATE THE MATRIX
local nvars 87 //Set nvars to the num of variables you have*/
local r 1
local c 1
matrix M = I(`nvars')
forvalues o = 1/`=_N' {
forvalues v = 1/`ncols' {
matrix M[`r', `c'] = var`v'[`o']
if `r' != `c' {
matrix M[`c', `r'] = M[`r', `c']
}
local ++c
if `c' > `r' {
local c = 1
if `r' < `nvars' {
local ++r
}
else {
continue, break
}
}
}
}
local names // BUILD A LIST OF NAMES TO APPLY TO BOTH ROWS AND COLUMNS
forvalues i = 1/87 { // 87 OR WHATEVER THE DIMENSION OF THE MATRIX IS
local names `names' var`i'
}
// RENAME THE ROWS AND COLULMNS Clyde Schechter's code
matrix rownames M = `names'
matrix colnames M = `names'
local names SINGLE MARRIED SEPARATE DIVORCED WIDOWED
HISORG
IRIBE YR_BIRTH SEQ_NUM MDXRCMP ORGRISK FORORG
CENTRAL UPPERIN LOWERIN UPPEROUT LOWEROUT AXILTAIL
OVERLAP LATERAL GRADE DX_CONF EOD10_SZ EOD10_EX
EOD10_NE ASPSURG CSTUMSIZ CSEXTEN LYMPOD10 CS5SITE
CS6SITE DAJCCT DAJCCN DAJCCSTG SURGPRIF SURGSITF
NUMNODES NO_SURG RADATION RADMIS RAD_SURG SS_SURG
SURGSITE ICD9V10V UNSPPSM EPITHPSM SQUAMPSM ADENCAR
CYTMUSER DUCTLOB HST_STGA A3SEERSG FIRSTPRM CTYMEDN
CTYPOV CTYPOV18 POVBIRTH CTYINCID HSEDSTAT COLEDUST
DXCTYCOL DXCTYHS DXSTRISK CODPUB STAT_REC SUMM2K
DETHCLSS CSTSEVAL CSRGEVAL CSMETVAL INTPRIM ERSTATUS
PRSTATUS SRVTIMON INSRECPB ADJTM6VL CSMETDX CS7SITE
HER2 BRST_SUB METBONPB METBRPB METLVPUB METLGPUB
T_VALUE N_VALUE M_VALUE
// 87 renamed
// give matrix M new names for rows and columns
matrix rownames M = `names'
matrix colnames M = `names'
matrix list M/*list your matrix to confirm accuracy of import and read in.
As Clyde points out, the number of variables in your data set
is equal to the dimension of the matrix*/
matrix symeigen X v = M
matrix list v/*list eigenvalues to spot a non positive definite
variance - covariance mtx.*/
cd c:\chest
c:\chest
. set more off
. clear
. import delimited c:\Mplus\oct292024montecarlovarcovmtx.txt
(1 var, 766 obs)
.
. // Clyde's revised Dec 6 2024 code follows
. split v1, gen(var) destring
variables born as string:
var1 var2 var3 var4 var5
var1 has all characters numeric; replaced as double
var2 has all characters numeric; replaced as double
var3 has all characters numeric; replaced as double
var4 has all characters numeric; replaced as double
(1 missing value generated)
var5 has all characters numeric; replaced as double
(1 missing value generated)
. drop v1
.
. // CREATE THE MATRIX
. local nvars 87 //Set nvars to the num of variables you have*/
. local r 1
. local c 1
.
. matrix M = I(`nvars')
.
. forvalues o = 1/`=_N' {
2. forvalues v = 1/`ncols' {
3. matrix M[`r', `c'] = var`v'[`o']
4. if `r' != `c' {
5. matrix M[`c', `r'] = M[`r', `c']
6. }
7. local ++c
8. if `c' > `r' {
9. local c = 1
10. if `r' < `nvars' {
11. local ++r
12. }
13. else {
14. continue, break
15. }
16. }
17. }
18. }
invalid syntax
r(198);
end of do-file
r(198);
Here is the complete do code I'm trying to run:
cd c:\chest
set more off
clear
import delimited c:\Mplus\oct292024montecarlovarcovmtx.txt
// Clyde's revised Dec 6 2024 code follows
split v1, gen(var) destring
drop v1
// CREATE THE MATRIX
local nvars 87 //Set nvars to the num of variables you have*/
local r 1
local c 1
matrix M = I(`nvars')
forvalues o = 1/`=_N' {
forvalues v = 1/`ncols' {
matrix M[`r', `c'] = var`v'[`o']
if `r' != `c' {
matrix M[`c', `r'] = M[`r', `c']
}
local ++c
if `c' > `r' {
local c = 1
if `r' < `nvars' {
local ++r
}
else {
continue, break
}
}
}
}
local names // BUILD A LIST OF NAMES TO APPLY TO BOTH ROWS AND COLUMNS
forvalues i = 1/87 { // 87 OR WHATEVER THE DIMENSION OF THE MATRIX IS
local names `names' var`i'
}
// RENAME THE ROWS AND COLULMNS Clyde Schechter's code
matrix rownames M = `names'
matrix colnames M = `names'
local names SINGLE MARRIED SEPARATE DIVORCED WIDOWED
HISORG
IRIBE YR_BIRTH SEQ_NUM MDXRCMP ORGRISK FORORG
CENTRAL UPPERIN LOWERIN UPPEROUT LOWEROUT AXILTAIL
OVERLAP LATERAL GRADE DX_CONF EOD10_SZ EOD10_EX
EOD10_NE ASPSURG CSTUMSIZ CSEXTEN LYMPOD10 CS5SITE
CS6SITE DAJCCT DAJCCN DAJCCSTG SURGPRIF SURGSITF
NUMNODES NO_SURG RADATION RADMIS RAD_SURG SS_SURG
SURGSITE ICD9V10V UNSPPSM EPITHPSM SQUAMPSM ADENCAR
CYTMUSER DUCTLOB HST_STGA A3SEERSG FIRSTPRM CTYMEDN
CTYPOV CTYPOV18 POVBIRTH CTYINCID HSEDSTAT COLEDUST
DXCTYCOL DXCTYHS DXSTRISK CODPUB STAT_REC SUMM2K
DETHCLSS CSTSEVAL CSRGEVAL CSMETVAL INTPRIM ERSTATUS
PRSTATUS SRVTIMON INSRECPB ADJTM6VL CSMETDX CS7SITE
HER2 BRST_SUB METBONPB METBRPB METLVPUB METLGPUB
T_VALUE N_VALUE M_VALUE
// 87 renamed
// give matrix M new names for rows and columns
matrix rownames M = `names'
matrix colnames M = `names'
matrix list M/*list your matrix to confirm accuracy of import and read in.
As Clyde points out, the number of variables in your data set
is equal to the dimension of the matrix*/
matrix symeigen X v = M
matrix list v/*list eigenvalues to spot a non positive definite
variance - covariance mtx.*/
Comment