Quartz | Level 8

## Amihud (2002) Liquidity Measure

Hello Folks

I am trying to implement the above-mentioned measure.  It is very straightforward measure.
Liquidity od stock month day d is;

=(1/number of valid observations in month) * (sum[abs(return(i, t, d)/volume(i,t,d))]

further, no of valid observation in a month must be more than 10.

my date format is yyyymmdd and all my variables are daily based. I am having difficulty in calculating no of valid days in a month.
kindly give me some code which can calculate no of valid days in a month.

so far i tried these codes

data illiquid;

set crspd;

Liquidity=abs(returns)/abs(volume); run;

I have problem in calculating no of valid days in a month.

1 ACCEPTED SOLUTION

Accepted Solutions
Opal | Level 21

## Re: Amihud (2002) Liquidity Measure

Because you have to count across multiple observations, you will need to take a few steps.  This is only one approach ... SAS usually provides alternatives that also work.

(1) Add YEAR and MONTH to the data set.

This sample code assumes that your dates are SAS dates.  If they are not, you will need to do this step differently.

data with_month;

set crspd;

year = year(date);

month =month(date);

run;

(2) Count "valid" dates per symbol, per month.

Since you haven't provided a definition of "valid", I will assume it means dates where volume > 0.

proc freq data=with_month;

tables symbol * year * month / noprint out=monthly_counts (drop=percent);

where volume > 0;

run;

proc sort data=with_month;

by symbol year month;

run;

(4) Merge in the number of valid days:

data want;

merge with_month monthly_counts (rename=(count=n_valid_days) in=have_counts);

by symbol year month;

if have_counts=0 then n_valid_days=0;

run;

That at least gets you N_VALID_DAYS on each observation to work with.  Presumably, you know where to go from there.  (Or perhaps you need to post a new question at that point.)

15 REPLIES 15
Quartz | Level 8

Super User

## Re: Amihud (2002) Liquidity Measure

Please post some sample data, expected output and your current not working code as well so we know where to start off. There are probably multiple approaches and if you're close there's no point in starting off from scratch.

Quartz | Level 8

## Re: Amihud (2002) Liquidity Measure

Thanks for replying. i got my issue fixed. i will post here my full codes so that anyone can use in future.
Good day

SAS Employee

## Re: Amihud (2002) Liquidity Measure

Hello -

If you have access to SAS/ETS software you may want to use the TIMESERIES procedure - in particular the OUTSUM data set should be of interest.

Example:

proc timeseries data=sashelp.citiday outsum=work.outsum out=_null_;
id date interval=day accumulate=total;
var SNYDJCM;
run;

Thanks,

Udo

Quartz | Level 8

## Re: Amihud (2002) Liquidity Measure

thank you very much for replying although I did not work for me. the codes provided by someone else did perfectly what I wanted.
still thank you I think I was not able to communicate my issue properly. I will post the full codes as soon I arrange them with proper notes.
Have a good day

Opal | Level 21

## Re: Amihud (2002) Liquidity Measure

Because you have to count across multiple observations, you will need to take a few steps.  This is only one approach ... SAS usually provides alternatives that also work.

(1) Add YEAR and MONTH to the data set.

This sample code assumes that your dates are SAS dates.  If they are not, you will need to do this step differently.

data with_month;

set crspd;

year = year(date);

month =month(date);

run;

(2) Count "valid" dates per symbol, per month.

Since you haven't provided a definition of "valid", I will assume it means dates where volume > 0.

proc freq data=with_month;

tables symbol * year * month / noprint out=monthly_counts (drop=percent);

where volume > 0;

run;

proc sort data=with_month;

by symbol year month;

run;

(4) Merge in the number of valid days:

data want;

merge with_month monthly_counts (rename=(count=n_valid_days) in=have_counts);

by symbol year month;

if have_counts=0 then n_valid_days=0;

run;

That at least gets you N_VALID_DAYS on each observation to work with.  Presumably, you know where to go from there.  (Or perhaps you need to post a new question at that point.)

Quartz | Level 8

## Re: Amihud (2002) Liquidity Measure

Thank you very much it worked for me and I am able to calculate the full Amihud(2002) measure I will post here the full codes if someone needs this to use in his/her research.
good Job and thank you again.

Calcite | Level 5

## Re: Amihud (2002) Liquidity Measure

Hello Raqthesolid,

Can you please share the code ? .. will be appreciated.

Thanks!

Quartz | Level 8

## Re: Amihud (2002) Liquidity Measure

Hello there,

the following codes worked for me. i hope they will help you too.

***Calculating liquidity from Daily data.;
*liquidity calculation following Amihud (2002) conditions;
2) At least 10 trading days in a month
3) Using daily data to calculate monthly Liquidity;

data Dailyp;
set daily;
Trans_month = MDY(MONTH (Date),1, YEAR(Date)); run;
proc sort; by trans_month; run;
data dailypa (Drop=Vol);
set dailyp;
prc=abs(prc);
if vol <= 0 then delete; *(-99 Volume is used when there are missing values);
if prc=. then delete;
if vol=. then delete;
Dvol=prc*vol; run;

**(2) Count "valid" dates per firm, per month. I assumed it means dates where volume > 0.;
proc freq data=dailypa;
tables symbol * year * month / noprint out=monthly_counts (drop=percent);run;
data Monthly_counts1;
set monthly_counts;*run; **(at least 10 trading days for each stock in a month;
if COUNT<10 then delete; run;

data illiquid;
set dailypa;
if ret=0 then delete;
ratio=abs(ret)/Dvol; run;

proc sort data=illiquid; by symbol year month; run;

proc summary data=illiquid nway;
class symbol year month;
var ratio;
output out=summary_data (keep=symbol year month total_ratio) sum=total_ratio; run;

proc sort data=summary_data;
by symbol year month; run;
proc sort data=monthly_counts1; by symbol year month; run;
data illiquidd;
merge summary_data monthly_counts1; by symbol year month; if count<5 then delete; run;

data mydata.Liquidity(drop=ratio2 total_ratio count symbol);
set illiquidd;
ratio2=10**6 *total_ratio; *(this is just to show in better form);
ILLIQUIDITY=ratio2/COUNT;
permno=symbol;
run;

proc sort;
by ILLIQUIDITY; run;
proc means;
var illiquidity ; run;

Good luck. let me know if you stuck anywhere and if my presentation is not very helpful.

Regards

ABdul

Calcite | Level 5

## Re: Amihud (2002) Liquidity Measure

Thanks a bunch for your response Abdul.

Best.

Trey

Obsidian | Level 7

## Re: Amihud (2002) Liquidity Measure

Hi Abdul

Thanks for sharing your codes. Trying to follow to obtain same measure but the section below is giving me errors.

**(2) Count "valid" dates per firm, per month. I assumed it means dates where volume > 0.;
proc freq data=dailypa;
tables symbol * year * month / noprint out=monthly_counts (drop=percent);run;

Did you create the year and month separately before running the codes as i have only date for each day.I did change the symbol =permno and was ok.

Thanks for the help in advance.regards.ejaa.

Quartz | Level 8

## Re: Amihud (2002) Liquidity Measure

Hello dear,
you can easily create year, month and day variables from your date. if your date is in sas date formate.
year = year(Date);
month = month(Date);
day = day(Date);
i did this because i have to calculated illiquidity on monthly basis from days. additionally i also wanted to see how many days are being used in each month. i require atlease 10 days in a month.

sorry for confusion among permno and symbol.. i originally used permno (USA data) and changed it for you. but few were left out. please assume permno, firmid or symbol as firmID .
hope this might help.
good day

Obsidian | Level 7

## Re: Amihud (2002) Liquidity Measure

Thanks very much for the explanation.I will effect the changes.However,  I want to calculate daily amihud illiquidity measure and will you codes work for that as well?thanks

Quartz | Level 8

## Re: Amihud (2002) Liquidity Measure

I did not do for Amihud (2002) and never saw it on daily as well. You can do it daily if you know some papers who did it. Otherwise other measures like spread, turnover etc might be more suitable on daily basis.

Discussion stats
• 15 replies
• 6871 views
• 8 likes
• 6 in conversation