STATA code 

Not the most complex code ever written but useful many times for me and perhaps useful for someone else too.