Hi Alison,
there are some errors with the syntax:
1. Comments are done via the "#" symbol
2. In Hansl (Gretl's scripting language) lines do not end by ";" symbol
Here is your script which runs fine here:
<hansl>
# Function to calculate Spearman correlations and p-values for a list of
variables
function matrix spearman_matrix(list variables)
matrix SC = {}
strings rnames = array(0)
n = nelem(variables)
loop i = 1..n
loop j = 1..i-1
# Calculate Spearman correlation and p-value
SC |= npcorr(variables[j], variables[i], spearman)
# Construct row names
rnames += sprintf("%s_%s", varname(variables[j]),
varname(variables[i]))
endloop
endloop
# Set column names
cnameset(SC, defarray("Spearman", "t-stat",
"p-value"))
# Set row names
rnameset(SC, rnames)
return SC
end function
# Open your dataset
# open panel2.gdt
open mroz87.gdt
# Specify the variables of interest
#list variables = deflist("ROE", "ENV", "SOC",
"GOV")
list variables = WHRS KL6 WA WE
# Calculate Spearman correlations and p-values
matrix SC_matrix = spearman_matrix(variables)
# Print the resulting matrix
print SC_matrix
</hansl>
Artur
Am 30.01.24 um 14:14 schrieb Alison Loddick:
> Hi All,
>
> I have never used Hansl or Gauss before and I am trying to work out how
> to get a programme working to create a matrix of spearman correlations.
> Allin created one last month, which I tried to run and kept getting ‘No
> redo information available’. Rather than coming running and asking for
> help I went to Chat GPT asked it what it meant which has gone over my
> head. I also asked it to decrible each line of the programme as I’ve
> done some programming decades ago. So I asked Chat gpt to create me a
> programme which is very similar to Allin’s but with my filename in and
> variable names in. I get the same error. I’m wondering if someone could
> direct me into what I should be doing. My data file is Panel2.gdt and I
> have four variable ROE, ENV,SOC and GOV. It is a panel datafile which
> is already set up as panel data. The programme from ChatGPT is the
> following. Please can someone be helpful to a novice I’m sure there is
> something very simple that I don’t know what to do.