* Mendota Ice Exercises *---------------------- * Setup: read the data into Stata with these commands infile str7 winter str6 close str6 open days using "http://www.ssc.wisc.edu/~hemken/Stataworkshops/Mendota2011.raw" generate year=real(substr(winter, 1, 4)) * Problem 1 *---------- * What what was the longest ice fishing season on record? * How many days long was it, and what was the year? * What was the shortest season? summarize days return list list year days if days==r(max) list year days if days==r(min) * Problem 2 *---------- * How common has it been to have 120 or more days of ice cover? * * (Hint: create an indicator.) generate longwinter = (days >=120) tabulate longwinter * Problem 3 *---------- * Would a person who grew up in the period 1900-1920 (like my * grandparents) be justified in thinking that "today's kids * have it easy"? Compare the mean duration of ice cover for * 1900-1920 versus 1990-2010. * * (Hint: You could drop unneeded observations with a "drop if" * command, or filter them with an indicator variable and * an "if" clause.) gen oldtimer = year < 1990 * drop if (year >= 1900 & year <=1920) | (year>=1990 & year <=2010) * another approach is to "filter" generate use = (year >= 1900 & year <=1920) | (year>=1990 & year <=2010) ttest days if use, by(oldtimer) * Problem 4 *---------- * When should we expect the Lake to open this spring? * * (Hint: convert the variable "open" to a day-of-the-year * by using the mdy() function or the date() function * and the %td format. Just getting the components for * mdy() or date() will be the hardest part of this * exercise. Use a constant year. Take the mean for a * simple prediction, and construct an optional confidence * interval. * If you know regression, predict a result for "2010". generate opendate=date(open+"-1960", "DMY") format %td opendate ci opendate /* not in the format we'd like*/ return list display %td r(lb) " " %td r(mean) " " %td r(ub) * better formating often takes work! regress days year /* we can use the coefficients to calculate a prediction, or */ predict dayspred format %td dayspred list dayspred if year==2010 /* ignore the 1960 part */ * another approach generate y2010 = year - 2010 regress days y2010 /* now the intercept is our answer */