On 30/01/2024 14:19, Artur T. wrote:
Hi Alison,
there are some errors with the syntax:
[...]
Here's a slight variation on Artur's script, that doesn't give you
tstats and pvalues, but what you get is more similar to a "traditional"
correlation matrix:
<hansl>
function matrix spearman_matrix(list variables)
n = nelem(variables)
strings names = varnames(variables)
matrix SC = I(n)
loop i = 1..n
loop j = 1..i-1
# Calculate Spearman correlation and p-value
scalar rij = npcorr(variables[j], variables[i], spearman)[1]
SC[i,j] = rij
SC[j,i] = rij
endloop
endloop
# Set row and column names
rnameset(SC, names)
cnameset(SC, names)
return SC
end function
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------