Counting in an unbalanced panel dataset

Reply
Occasional Contributor
Posts: 5

Counting in an unbalanced panel dataset

Hi everybody,

1. I need help with the following. I have monthly return data. The dataset is an unbalanced panel. Can anybody help with the program?

2. Also when you run panel regression with FE in SAS how can you retrieve the within-observations r-square? I am able to get the o verall r-square from a proc glm but don't know how to get the within-observations r-square.

Thanks a lot for your help,

JP

What I haveWhat I want
monthfirm returnmonthfirm returnlagreturn
Jan-0010010.5Jan-0010010.5
Feb-0010010.7Feb-0010010.70.5
Mar-0010010.8Mar-0010010.80.7
Apr-0010010.9Apr-0010010.90.8
Sep-0110010.3Sep-0110010.3
Oct-0110010.4Oct-0110010.40.3
Nov-0110010.5Nov-0110010.50.4
Dec-0110010.6Dec-0110010.60.5
Jan-0210010.7Jan-0210010.7
Feb-0210010.8Feb-0210010.80.7
Mar-0210010.9Mar-0210010.90.8
Apr-0210010.1Apr-0210010.10.9
May-0210010.2May-0210010.20.1
Jun-0210010.3Jun-0210010.30.2
Jul-0210010.4Jul-0210010.40.3
Aug-0210010.5Aug-0210010.50.4
Sep-0210010.6Sep-0210010.60.5
Oct-0210010.7Oct-0210010.70.6
Nov-0210010.8Nov-0210010.80.7
Dec-0210010.9Dec-0210010.90.8
Jan-0210020.1Jan-0210020.1
Feb-0210020.2Feb-0210020.20.1
Mar-0210020.3Mar-0210020.30.2
Apr-0210020.4Apr-0210020.40.3
May-0210020.5May-0210020.50.4
Jun-0210020.6Jun-0210020.60.5
Jul-0210020.7Jul-0210020.70.6
Aug-0210020.8Aug-0210020.80.7
Sep-0210020.9Sep-0210020.90.8
Oct-0210020.1Oct-0210020.10.9
Nov-0210020.2Nov-0210020.20.1
Dec-0210020.3Dec-0210020.30.2
Occasional Contributor
Posts: 5

Re: Counting in an unbalanced panel dataset

I already found the solution in SAS Community. The link is given above. I adjusted the code as following:

data want;

     set have end=eof;

        by permno date;

            if not eof then set test(firstobs=2 keep=date rename=date=nextdate);

                m = ifN(not last.permno,intCK('MONTH',date,nextdate),1)-1;

                    do i = 0 to m;

                        ndate = intNX('MONTH',date,i);

                         lagreturn = lag1(return);

                        if first.permno and i eq 0 then lagreturn = .;

                    output;

                return = .;

            end;

format ndate monyy.;

run;

data want; set want; where lagreturn <> . and return <> . ; run;

I still haven't figured how to retrieve the within-observations r-square though.

Thanks for your help,

JP

Ask a Question
Discussion stats
  • 1 reply
  • 233 views
  • 0 likes
  • 1 in conversation