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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1031 views
  • 4 likes
  • 2 in conversation