Statistical Procedures

Programming the statistical procedures from SAS
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Princeelvisa
Obsidian | Level 7

Please i need help with writing a code to calculate the equation below ...

It is a rank inverse-weighting scheme that assigns higher weights to more recent observations.

For each fund j and quarter t , i want to compute the weighted average of β j,t during the fund’s history up to quarter t, with weights that vary inversely with the distance of the coefficients from quarter t . Thank you.

Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Princeelvisa,

 

If your input dataset is sorted by j and t , where t=1, 2, 3, ... (cf. below test dataset HAVE), you can use the code suggested below (creating dataset WANT) for the computation of FHj,t.

/* Create sample data */

data have;
input j t beta;
cards;
1 1 100
1 2 110
1 3 108
1 4 117
1 5 120
2 1 200
2 2 222
2 3 212
2 4 228
;

/* Compute FH values */

data want(drop=_:);
array _b[999] _temporary_;
call missing(of _b[*]);
do until(last.j);
  set have;
  by j;
  _b[t]=beta;
end;
do until(last.j);
  set have;
  by j;
  FH=0; _w=0;
  do _h=1 to t;
    FH+_b[t-_h+1]/_h;
    _w+1/_h;
  end;
  FH=FH/_w;
  output;
end;
run;

This assumes at most 999 quarters per fund (see array dimension).

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @Princeelvisa,

 

If your input dataset is sorted by j and t , where t=1, 2, 3, ... (cf. below test dataset HAVE), you can use the code suggested below (creating dataset WANT) for the computation of FHj,t.

/* Create sample data */

data have;
input j t beta;
cards;
1 1 100
1 2 110
1 3 108
1 4 117
1 5 120
2 1 200
2 2 222
2 3 212
2 4 228
;

/* Compute FH values */

data want(drop=_:);
array _b[999] _temporary_;
call missing(of _b[*]);
do until(last.j);
  set have;
  by j;
  _b[t]=beta;
end;
do until(last.j);
  set have;
  by j;
  FH=0; _w=0;
  do _h=1 to t;
    FH+_b[t-_h+1]/_h;
    _w+1/_h;
  end;
  FH=FH/_w;
  output;
end;
run;

This assumes at most 999 quarters per fund (see array dimension).

Princeelvisa
Obsidian | Level 7
Thank you so much @ FreelanceReinhard, it worked awesomely. Thank you once again.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1335 views
  • 4 likes
  • 2 in conversation