Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: using invnorm uniform to normalize my liquidity measure

 From Nick Cox To "statalist@hsphsun2.harvard.edu" Subject Re: st: using invnorm uniform to normalize my liquidity measure Date Fri, 17 May 2013 17:15:57 +0100

```This is rather difficult to follow, but I can help a bit.

Please note first that minimal name (date) references are deprecated
on Statalist, as you will see if you read the FAQ, as you were asked
to do before posting. Fortunately the references don't seem important

You are using random normal deviates when it seems that you want
something completely different, namely to do something using  the mean
and SD. -mean()- and -sd()- are -egen- functions, so that should be
straightforward.

Also, -egen- only works with calls to -egen- functions, and
-invnormal()- and -uniform()- are not -egen- functions. That's why
your syntax is illegal as well as wrong for what you want to do.

Incidentally, in Stata 12.0 -rnormal()- is by far the best way of
getting random normal deviates. Using -invnorm()- and -uniform()- will
still work, but -rnormal()- has been the dedicated function for some
versions now.

In terms of your problem, it sounds as if you are dealing with numbers
that can be very big or very small, in which case I recommend -double-
variable types.

bysort permno dm: egen double ret_div_vol=total(abs(ret/vol))
bysort permno dm: gen double illiq=1e6 * ret_div_vol / validobs

I put some extra simplifications in there at the same time.

You should -update- your copy of Stata, or get a systems person to do that.

Nick
njcoxstata@gmail.com

On 17 May 2013 16:52, Yori van der Kruijs <yorivdkruijs@hotmail.com> wrote:

> For my master thesis I'm trying to replicate and extend the liquidity CAPM as used by Acharya and Pederson (2005).
> In short, I need to construct a liquidity measure and liquidity portfolios to be able to investigate whether low liquidity stocks obtain higher expected returns than high liquidity stocks.
>
> I use the liquidity measure from Amihud (2002) (it's called ILLIQ-measure)
> It is very straightforward. ILLIQ of stock i in month t is:
> ILLIQ(i,t)= (1/Number of valid observations in month)* Sum[ (ABS(Return(i,t,d))/Volume(i,t,d))]
>
> The second part of the equation is the summation of absolute returns and dollar volume on day d in month t.
>
> Note: They multiply ILLIQ by 1.000.000 (1 million) for analytic purposes.
>
> In STATA I already constructed the ILLIQ measure itself, using this code:
>
>    bysort permno dm: egen ret_div_vol=sum(abs(ret/vol))
>    bysort permno dm: gen illiq=ret_div_vol*(1/validobs)*1000000
>
> permno is the id variable, dm the monthly time variable (e.g. 2001m1, 2001m2 etc.)
>
> Where I face problems:
>
> They state that ILLIQ is measured in percent per dollar, while their model is in terms of "dollar cost per dollar invested".
> They solve this problem by normalizing illiq, creating c(i,t):
>
> c(i,t)=min(0.25 + 0.30* ILLIQ(i,t) * P(m,t-1), 30)
>
> Ignore the P(m,t-1) factor here.
>
> (My question:) I only need to know how to implement the mean (0.25) and standard deviation (0.30 * ILLIQ(i,t))
> in STATA which returns the same value for a firm on different days in the same month.
>
> Now I use:
>
>   bysort permno dm: gen normilliq=min(invnorm(uniform())*(0.30*illiq)+0.25,30)
>
> This however creates values which are different for each observation of the same firm in the same month.
> Since the ILLIQ measure creates values which are equal for a given firm for every day in a given month, the normalized measure should also give those results.
>
> I tried using the standard "egen" function in combination with invnorm(uniform()), but I received this:
>    bysort permno dm: egen normilliq=invnorm(uniform())*(0.30*illiq)+0.25
>               unknown egen function invnorm()
> Suggesting that this is not possible using "egen"
>
>
> I am using Stata/SE 12.0 for Windows (64-bit x86-64)
> Revision 24 Aug 2011
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```