We hyphenate compounds when they appear before a noun. For example: fire-resistant curtains, fixed-rate mortgages, out-of-date credit cards. We do this to avoid confusion. Compare the following:
an old furniture salesman -and- an old-furniture salesman
The first one indicates that the salesman is old, while the second is just a person who sells old furniture. In your question, then, two-year study would be correct.