Tuesday, April 9, 2013

A Beginner's Observations with STATA

This year, I have been occupied with a real estate finance project through the Undergraduate Research Opportunities Program here at the University of Michigan. Below are some observations about STATA that may be of use for some people.


1. Macros are useful, but rather peculiar. As a first time user, I found it very difficult to differentiate between when I should use "`variable'" and `variable'. From what I see, any time that the variable is meant to denote a string, it should be enclosed as "`variable'", whereas if it supposed to be a variable call or something of that sort, it should be`variable'

2. STATA is programmable, but not necessarily a 'programming' language. When working in STATA, you don't really have the flexibility that you would have in R or Python. It's difficult to make arbitrary functions, and sometimes I just want to say "int x = 4;", but there's no natural way to implement that. Another STATA construct that I had to familiarize myself with was the "foreach" command. It does do a natural way of iterating over an array in other languages, but I often get caught typing "for" by mistake.
3. If only I understood if's, my life would be easier. In STATA, there's two kinds of if's, one is a qualifier, and one is the standard if in programming that changes the flow of the program. For example, if I were to say
count if smsa == 0320
It would count the number of observations whose smsa variable entry was 0320. On the other hand, if I had
if(`nat'){
di "Merging with smsa control"
merge 1:1 smsa control using "tmortg`y'_`d'"
}
else{
di "Merging with control"
merge 1:1 control using "tmortg`y'_`d'"
}
The program would merge the file by smsa control if `nat' is true, and it would merge by just control otherwise.

4. On the above note, it may be useful to put a few display statements in your code. It's helpful to see  in the log where the program went, especially when there's these flow control issues.

5. While writing functions may be hard, it is certainly not impossible. To this end, the guide by Roy Mill was invaluable for me. I was able to more effectively abstract my code and reconcile it with my programming instincts.

6. Careful with do files and local variables. After I declared local variables in my do files, I could not access them once I was back in interactive mode. However, I had no problem with those local variables when I was working within the do file.

And for those STATA veterans among you, is there any way to do error handling? In Java, C++, Python, and R, there are tryCatch constructs that can keep the program running even if a variable is missing. This would be useful because it would allow the program to try to do something, and then if that doesn't work I would like to make the program go down a different path.

Any additional advice on STATA would be appreciated. Hope my observations can help some others avoid (too much) frustration.

Monday, April 8, 2013

Reaching for Yield


Reaching for yield from Yichuan Wang

This was a presentation on 'reaching for yield' that  I prepared for my investment club, Michigan Interactive Investments. The argument is the same as in Jeremy Stein's speech. In low interest rate environments, pension fund managers go into riskier assets in order to reach their benchmark yields. Therefore, this should result in high beta stocks having lower risk-adjusted returns. I test this hypothesis using stock price data from the past five years on almost all stocks listed on the U.S. exchanges, and find that there did seem to be a substantial amount of 'reaching for yield' in 2011 and 2012, and that in 2011 this phenomenon was concentrated in the large cap stocks whereas now more of the effect seems to be with the small cap stocks.

While I'm not that confident on the exact quantitative magnitudes, reaching for yield does seem like a new channel through which nominal shocks can have real effects. Given the plausible assumption that most benchmarks are nominal in nature, then deflation has the added cost of inducing excess risk taking. This suggests that after financial crises, monetary policy should be even more aggressive in order to minimize the extent of the reach for yield.

I do think this investigation brings up an important methodological issue. I believe future macroeconomic research will rely much more heavily on observations from financial markets. This was the method recently used to measure the effect of sticky prices, and this technique of disaggregating financial data to lend support to macroeconomic theories is quite intriguing. The advantage that this has over traditional data sources is that you have a much higher frequency data stream in finance. This allows more in-depth analysis on focused time periods -- something that is much harder to do with regular CPI data.

In addition, through working on this I have found data analysis through open source R to be quite powerful. I generated all the plots in the presentation with the R package ggplot2, and all the stock price data came from Yahoo Finance interfaced through quantmod. Coupled with the powerful regression algorithms in R, I could generate the desired coefficients from weighted regressions and draw them on a plot.