Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: display formatted table of sorted factor loadings


From   Dirk Enzmann <[email protected]>
To   [email protected]
Subject   st: display formatted table of sorted factor loadings
Date   Tue, 17 Nov 2009 14:59:27 +0100

I wrote a small .ado to sort rotated factor loadings by size and save the result into a matrix e(r_Ls). It also creates a matrix e(Psis) where the items are sorted in the same way as in e(r_Ls) (I'm not sure whether it needs version 10, 11, or even 9):

* ---------------------------
program sortloadings
version 10
if (length("`e(r_class)'") == 0) {
	dis as err "factor rotation results not found"
	error 301
}
mata: sortL()
matrix list e(r_Ls)
* matrix list e(Psis)
end
version 11
mata:
void sortL()
{
  rNames=st_matrixrowstripe("e(r_L)")
  cNames=st_matrixcolstripe("e(r_L)")
  ld=st_matrix("e(r_L)")
  Psi=st_matrix("e(Psi)")
  rNamesPsi=st_matrixrowstripe("e(Psi)")
  cNamesPsi=st_matrixcolstripe("e(Psi)")
  f=cols(ld)
  vars = rows(ld)
  loadmax = abs(ld):==rowmaxabs(ld)
  ld = ld, (1::vars)
  for (i=1; i<=f; i++) {
    if (i==1) ldsorted = sort(select(ld,loadmax[,i]),-i)
    else ldsorted = ldsorted \ sort(select(ld,loadmax[,i]),-i)
  }
  sortindex = ldsorted[,f+1]
  ldsorted = ldsorted[,1::f]
  rNames = rNames[sortindex,]
  Psi = Psi[,sortindex]
  cNamesPsi = cNamesPsi[sortindex,]
  st_matrix("e(r_Ls)",ldsorted)
  st_matrixcolstripe("e(r_Ls)",cNames)
  st_matrixrowstripe("e(r_Ls)",rNames)
  st_matrix("e(Psis)",Psi)
  st_matrixcolstripe("e(Psis)",cNamesPsi)
  st_matrixrowstripe("e(Psis)",rNamesPsi)
}
end
* ---------------------------

The .ado works fine. However, I don't know how to use the matrix e(r_Ls) together with the matrix e(Psis) to display a table of the sorted loadings in the same nicely formatted way as the "Rotated factor loadings ..." are displayed by -rotate-.

Is there a short and/or easy way of displaying such a table, perhaps by using routines of other .ados? (To demonstrate how this could be done one could use e(r_L) and e(Psi) that are created by -factor- followed by -rotate-).

*************************************************
Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Schlueterstr. 28
D-20146 Hamburg
Germany

phone: +49-(0)40-42838.7498 (office)
       +49-(0)40-42838.4591 (Mrs Billon)
fax:   +49-(0)40-42838.2344
email: [email protected]
www: http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html
*************************************************
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index