# Kernel regression - kreg

Dear Friends/Colleagues

I am quite new to this.

I have been trying to implement kernel regression in Gauss using the kreg function/program. I have compiled the following codes based on the simulation codes by Wang and Phillips (2009). The code appears to run OK but I can't seem to able to print/show the regression results. A key command at the which prints/shows results is probably missing.

``````new;

proc( 2 ) = kreg(y,x,xf,hpower);
local n,tvec,gam,arg,ker,ghat,m,denom;
n = rows(y); @ rows x & y the same @
m = rows(xf); @ rows of xf in : mt(xf) = sum{(K(xf-xs)*ys}/sum(K(xf-xs)@
tvec = x;
gam = 1/n^hpower;
arg = (xf*ones(1,n)-ones(m,1)*tvec')/gam;
ker = pdfn(arg);
denom = sumc(ker');
ghat = (ker*y)./sumc(ker');
retp(ghat,denom);
endp;``````

Can anyone kindly help me complete the code so that I can immediately begin empirical applications. My current paper is in limbo just because of this. Any help would be highly appreciated.

Kind regards,

1
accepted

The code that you posted loads your data and then defines a GAUSS procedure that you can use, but never calls the procedure. You need to define what all the inputs should be, call the procedure and then print out the results with the print command like this:

``````//Clear all matrices and data from workspace
new;

//TODO: Define 'xf' input
//Don't forget to end line with semi-colon
xf =

//TODO: Define 'hpower' input
//Don't forget to end line with semi-colon
hpower =

//Call kreg procedure
{ ghat, denom } = kreg(y, x, xf, hpower);

//Print output
print "ghat = " ghat;
print "denom = " denom;

//Define what 'kreg' procedure should do
proc( 2 ) = kreg(y,x,xf,hpower);
local n,tvec,gam,arg,ker,ghat,m,denom;
n = rows(y); @ rows x & y the same @
m = rows(xf); @ rows of xf in : mt(xf) = sum{(K(xf-xs)*ys}/sum(K(xf-xs)@
tvec = x;
gam = 1/n^hpower;
arg = (xf*ones(1,n)-ones(m,1)*tvec')/gam;
ker = pdfn(arg);
denom = sumc(ker');
ghat = (ker*y)./sumc(ker');
retp(ghat,denom);
endp;``````
0

I can't thank you enough for your prompt polishing of my codes. This will improve the quality of research greatly.

Sincerely,

### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.