“April weather” – is it real?

“April weather”, we would say. It was a simple fact of life, as inevitable as death and taxes, and to be endured with the same humility. The weather in April just sucked. After March’s promise of spring, April was a throwback into darker, colder times.

We even have a country saying: “April, April, der macht, was er will” (“April, April does whatever it wants”). It conjures up the reign of a despotic weather god submitting the land to unpredictable conditions. And indeed, weather sites are happy to explain to you the exact meteorological constellations that make April as changeable and unpleasant as no other month (e.g. here).

It’s a strange truth that we often do not question things we’ve grown up with, as easy to test and as implausible they may seem once we think about them. It took me decades to question the validity of folk wisdom about the capriciousness of April, but, finally, here I am, armed with some data and a great program to analyze them! I take common perceptions to assert at least two things: The weather in April is particularly bad; and it is particularly changeable. “Particularly bad” means “worse than expected”, and that in turn can be naturally interpreted as something like “noticeably lower than the mid-point between March and May”. Changeability simply means a lot of fluctuations in weather conditions during that month.

 

Is April weather worse?

I use the same data as for my first post, exclude the two mountain locations and end up with 6 stations in Switzerland with data from 1979-2013. First, to rule out artifacts, let’s make sure missing values have no particular relation to April.

gr bar (count) tmax tmin tdiff tavg sun rain clouds snow, over(month) legend(size(vsmall))

 

They don’t.
So what’s the weather like in April, compared to immediately previous and subsequent months? Here are plots of monthly averages for T max, T min, rainfall and sunshine hours:
 

line_allyr_tmaxmeanmt_FebJun

line_allyr_tminmeanmt_FebJun

line_allyr_rainmeanmt_FebJun

line_allyr_sunmeanmt_FebJun

 

loc tis `"`"T max [°C]"' `"T min [°C]"' `"Rainfall [l/mm2]"' `"Sunshine duration [h]"'"'
loc j=1
foreach var of varlist tmaxmeanmt tminmeanmt rainmeanmt sunmeanmt {

	loc ti : word `j++' of `tis'

	tw 																			/// =
	(line `var' year if month==2)												///
	(line `var' year if month==3)												///
	(line `var' year if month==4)												///
	(line `var' year if month==5)												///
	(line `var' year if month==6)												///
	, by(																		///
		 station,  note(" ") rows(2) 											///
	     ti(`ti')					///
	  ) 																		///
	 subtitle(, size(small)) ytitle(" ", size(small)) 							///
		yla(, labs(small) grid glwidth(vvvthin) glcolor(gs14) glpattern(solid)  ///
		nogextend) xtitle(" ")		  											///
		xlabel(, labsize(small))	 											///
		legend(order(1 "Feb" 2 "Mar" 3 "Apr" 4 "May" 5 "Jun"))					///
		name(line_allyr_`var'_FebJun, replace)

	gr export line_allyr_`var'_FebJun.png, replace
}

 

I see three interesting patterns. First, April temperatures are well behaved. They seldom breach the boundaries set by March and May. On a second look, you can see that they are consistently closer to those of March than those of May. In fact, T min never ever crosses over into May territory, while it occasionally visits March land. Temperature separation is about 3-5° on either side of April.

Second, since about the turn of the millennium, April temperatures are moving away from March and towards May. It is as if something is driving a wedge between March, which remains at constant levels, and April, which is pushed into an upward trend. I’m sure meteorologists can explain this. It looks as though April could soon be getting rid of its bad boy image, at least temperature-wise.

Third, amounts of sunshine and rain are not nearly as neatly separated by month. They strongly overlap, but it is still roughly true that April lies in the middle of a series of ascending values from February to June.

My first conclusion is that, although there is some truth to the idea that April is cooler than expected assuming a linear increase of temperature across months, the difference to March is only about 1° smaller than the difference to May. We can confirm this by running a multilevel linear regression using Stata’s xtmixed. The predicted difference in, for example, T max between  March and April is 3.7°, and that between April and May is 4.5°, a mere 0.8° more.

 

xtmixed tmaxmeanmt ib4.month year || station:, nolog vsquish noretable
------------------------------------------------------------------------------
  tmaxmeanmt |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       month |
          1  |    -10.818      0.190   -57.02   0.000      -11.190     -10.446
          2  |     -8.840      0.190   -46.59   0.000       -9.211      -8.468
          3  |     -3.747      0.190   -19.75   0.000       -4.119      -3.375
          5  |      4.547      0.190    23.97   0.000        4.175       4.919
          6  |      8.016      0.190    42.25   0.000        7.644       8.388
          7  |     10.489      0.190    55.28   0.000       10.117      10.861
          8  |      9.963      0.190    52.51   0.000        9.591      10.335
          9  |      5.538      0.190    29.19   0.000        5.166       5.910
         10  |      0.183      0.190     0.96   0.335       -0.189       0.555
         11  |     -6.285      0.190   -33.12   0.000       -6.657      -5.913
         12  |     -9.953      0.190   -52.46   0.000      -10.325      -9.581
        year |      0.046      0.004    12.04   0.000        0.039       0.054
       _cons |    -77.052      7.668   -10.05   0.000      -92.081     -62.023
------------------------------------------------------------------------------

 

Is April weather more changeable?

My first thought was to simply compute standard deviations to compare the variability of weather conditions among months. But you might already guess the problem: variability does not necessarily mean changeability, i.e. a high rate of fluctuations over the course of a month. April could be starting with low temperatures and monotonously increase them to high values. That would yield a sizeable standard deviation but nothing that we would call changeable. Instead, we need something that tracks the magnitude of day-to-day “jumps” in weather conditions. What I ended up with was to simply sum up the absolute values of change between consecutive days. This index will yield the highest values when measures are bouncing up and down from one day to the next, and zero when they remain constant. The case described above with a monotonous increase (or decrease) will give only moderate values, which is as it should be.

And here are the plots of the changeability score:

 
line_tmaxfluctmt_FebJun

line_tminfluctmt_FebJun

line_allyr_rainmeanmt_FebJun

line_allyr_sunmeanmt_FebJun

 

// changeability/fluctuations across days of month

loc tis `"`"T max [°C]"' `"T min [°C]"' `"Rainfall [l/mm2]"' `"Sunshine duration [h]"'"'
loc j=1

foreach var of varlist tmaxfluctmt tminfluctmt sunfluctmt rainfluctmt {

	loc ti : word `j++' of `tis'

	tw 																			/// =
	(line `var' year if month==2)												///
	(line `var' year if month==3)												///
	(line `var' year if month==4)												///
	(line `var' year if month==5)												///
	(line `var' year if month==6)												///
	, by(																		///
		 station,  note(" ") rows(2) 											///
	     ti("`ti': changeability across days of month")							///
	  ) 																		///
	 subtitle(, size(small)) ytitle(" ", size(small)) 							///
		yla(, labs(small) grid glwidth(vvvthin) glcolor(gs14) glpattern(solid)  ///
		nogmin nogextend) xtitle(" ")  											///
		xlabel(, labsize(small))	 											///
		legend(order(1 "Feb" 2 "Mar" 3 "Apr" 4 "May" 5 "Jun"))					///
		name(line_`var'_FebJun, replace)

	gr export line_`var'_FebJun.png, replace
}

 

Again, some patterns strike the eye. February has noticeably lower fluctuation rates of T max, rainfall, and, to a certain extent, sunshine duration. It’s the only trace that can be visually separated from the others. The rest of the months look chaotic, with no clear pattern. They seem to take random turns at being highest. But since appearances can be deceptive, I ran another round of multilevel regression models (this time including all the 12 months, just for kicks):

fluctmt_margins_combined

 

foreach var of varlist tmaxfluctmt tminfluctmt sunfluctmt rainfluctmt {
	qui xtmixed `var' ib4.month year || station:, nolog vsquish noheader noretable
	qui margins month, atmeans
	marginsplot, ti(`var') name(`var'_margins, replace) nodraw
}
gr combine tmaxfluctmt_margins tminfluctmt_margins sunfluctmt_margins rainfluctmt_margins, altshrink nocopies

 

April doesn’t stand out in these margins plots, with the exception of the one for T max, where it is among the three highest values. Note, however, that the other ones in the top three are the neighboring months March and May, so it’s hard to see how April could be perceived as an outlier in terms of temperature highs when it fits so nicely with the rest of the trio.
 

The end of the myth?

All in all, nothing particular seems to be going on meteorologically in April that would justify its bad reputation. So – wow! – have I just shown common beliefs about April weather to be a myth?!

Well, not so fast, tiger. There are a dozen reasons why my analysis might not prove much. I’m no meteorologist, so might have overlooked something important about the data. The analysis might not have gone deep enough. The number of weather stations might be too small and/or not representative, not for Switzerland, let alone for the other German-speaking countries. And so on. Despite all of this, I was still ready to say that my results are not compatible with popular wisdom and cast doubt on the notion of “April weather” and its unpredictability. And, with that little bit of insight, I would have happily rested my case.

Enter my bright nephew S, a geographer. Over a fine vegetarian meal at tibits, I told him about my forthcoming blog post. He thought about it for a while, then said “Hmm”, and then: “Changeability could also mean that the weather fluctuates not over the course of a month, but over the course of the years.”

Ah yes! Great thought and I had completely missed it. It might indeed be that any given April isn’t particularly changeable, but that consecutive Aprils have significantly different average weather. So take a look at this:

 
bar_sunmeanmtfluctyr_2

 

I was stoked when I saw this. At every location, April shows the highest year-to-year fluctuation in daily sunshine hours of all months, and the differences are all statistically significant (to check this, I ran xtmixed sunmeanmtfluctyr ib4.month || station:).

But let’s examine this more closely. April has about 17 hours more year-to-year fluctuations over 35 years (1979-2013) than March. On average, this amounts to half an hour more change between two consecutive years. And this, in turn, means that the amount of sunshine an average April day gets changes yearly by half an hour more than the amount of sunshine an average March day gets.

Collapsed over all years, March gets an average of 4 h 50 min of daily sunshine, while April gets 5 h and 40 min. The half hour of added fluctuation for April therefore equals roughly 10% of the average daily exposure to sunlight.

The tough question is whether this difference would make a difference to people’s experience, enough for them to build a stable perception of April as being more changeable from year to year than its preceding months. I don’t find it entirely inconceivable that you would notice that the current April has half an hour of sunshine more or less every day compared to last year’s,  especially when you only get 5 hours of it on average in that month. On the other hand, I find it more plausible that people’s experience would be driven largely by changes between subsequent months within a single year and not by changes of a single month between subsequent years.

We’re left with the ever-fascinating uncertainty of data – or, rather, their interpretation. This is a scientist’s daily meal, and although people like to hear a good story at least as much as to observe the weather, science rarely ever delivers the black-and-white findings the media like so much. However, in the present case, an expert in meteorology might easily cut through the mist of my dilettante analysis and reveal to us the truth behind “April weather”.

 


Materials

// Aprilwetter - April weather

// load the EUROPEAN CLIMATE ASSESSMENT & DATASET (ECA&D) as described in the first post

// daily averages over months
bysort station year month: egen tdiffmeanmt = mean(tdiff)
bysort station year month: egen tavgmeanmt = mean(tavg)
bysort station year month: egen tmaxmeanmt = mean(tmax)
bysort station year month: egen tminmeanmt = mean(tmin)
bysort station year month: egen rainmeanmt = mean(rain)
bysort station year month: egen snowmeanmt = mean(snow)
bysort station year month: egen sunmeanmt = mean(sun)
label var tdiffmeanmt     "Daily maximum temperature difference, monthly mean"
label var tavgmeanmt     "Daily average temperature, monthly mean"
label var tmaxmeanmt     "Daily maximum temperature, monthly mean"
label var tminmeanmt     "Daily minimum temperature, monthly mean"
label var rainmeanmt     "Daily rainfall, monthly mean"
label var snowmeanmt     "Daily snowfall, monthly mean"
label var sunmeanmt     "Daily sunshine hours, monthly mean"

// N of non-missing values
gr bar (count) tmax tmin tdiff tavg sun rain clouds snow ///
if station!=1649 & station!=243, over(month) legend(size(vsmall))

// summing up differences betw consecutive days as a measure of fluctuation
foreach v of varlist tmax tmin tdiff tavg sun rain snow {
    bysort station year month (dayy): gen `v'consecdiff = abs(`v'[_n]-`v'[_n+1])
    bysort station year month: egen `v'fluctmt = total(`v'consecdiff)
    drop `v'consecdiff
}

// collapse data over days of month
collapse (mean) tdiffmeanmt tavgmeanmt tmaxmeanmt tminmeanmt    ///
    rainmeanmt snowmeanmt sunmeanmt tmaxfluctmt tminfluctmt        /// 
    tdifffluctmt tavgfluctmt sunfluctmt rainfluctmt snowfluctmt ///
    (sd) tdiffsdmt=tdiff tavgsdmt=tavg tmaxsdmt=tmax             ///
    tminsdmt=tmin rainsdmt=rain snowsdmt=snow sunsdmt=sun        ///
    , by(station year month)


// summing up differences betw consecutive years as a 2nd measure of fluctuation
foreach v of varlist tdiffmeanmt tavgmeanmt tmaxmeanmt tminmeanmt    ///
    rainmeanmt snowmeanmt sunmeanmt {
    bysort station month (year): gen `v'consecdiff2 = abs(`v'[_n]-`v'[_n+1])
    bysort station month: egen `v'fluctyr = total(`v'consecdiff2)
    drop `v'consecdiff2
}

gen febjun = month if !(month<2 | month>6)
drop if station==1649 | station==243
label define month 1 "Jan" 2 "Feb" 3 "Mar" 4 "Apr" 5 "May" 6 "Jun" 7 "Jul" ///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;8 "Aug" 9 "Sep" 10 "Oct" 11 "Nov" 12 "Dec"
label value month month
label define febjun 2 "Feb" 3 "Mar" 4 "Apr" 5 "May" 6 "Jun"
label value febjun febjun


// graph mothly weather measures (T max, T min, rain, sun) over years

loc tis `"`"T max [°C]"' `"T min [°C]"' `"Rainfall [l/mm2]"' `"Sunshine duration [h]"'"'
loc j=1
foreach var of varlist tmaxmeanmt tminmeanmt rainmeanmt sunmeanmt {
&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;loc ti : word `j++' of `tis'
&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;tw &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;/// =
&nbsp;&nbsp; &nbsp;(line `var' year if month==2)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;(line `var' year if month==3)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;(line `var' year if month==4)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;(line `var' year if month==5)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;(line `var' year if month==6)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;, by(&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; station,&nbsp; note(" ") rows(2) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ti(`ti')&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp; ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp; subtitle(, size(small)) ytitle(" ", size(small)) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;yla(, labs(small) grid glwidth(vvvthin) glcolor(gs14) glpattern(solid)&nbsp; ///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;nogextend) xtitle(" ")&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;xlabel(, labsize(small))&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;legend(order(1 "Feb" 2 "Mar" 3 "Apr" 4 "May" 5 "Jun"))&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;name(line_allyr_`var'_FebJun, replace)

}

// multilevel linear regression of T max on month and year
xtmixed tmaxmeanmt ib4.month year || station:, nolog vsquish noretable


// changeability/fluctuations across days of month

loc tis `"`"T max [°C]"' `"T min [°C]"' `"Rainfall [l/mm2]"' `"Sunshine duration [h]"'"'
loc j=1

foreach var of varlist tmaxfluctmt tminfluctmt sunfluctmt rainfluctmt {

&nbsp;&nbsp; &nbsp;loc ti : word `j++' of `tis'

&nbsp;&nbsp; &nbsp;tw &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;/// =
&nbsp;&nbsp; &nbsp;(line `var' year if month==2)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;(line `var' year if month==3)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;(line `var' year if month==4)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;(line `var' year if month==5)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;(line `var' year if month==6)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;, by(&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; station,&nbsp; note(" ") rows(2) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ti("`ti': changeability across days of month")&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp; ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp; subtitle(, size(small)) ytitle(" ", size(small)) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;yla(, labs(small) grid glwidth(vvvthin) glcolor(gs14) glpattern(solid)&nbsp; ///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;nogmin nogextend) xtitle(" ") &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;xlabel(, labsize(small))&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;legend(order(1 "Feb" 2 "Mar" 3 "Apr" 4 "May" 5 "Jun"))&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;name(line_`var'_FebJun, replace)

}

// multilevel linear regressions of changeability on month and year
foreach var of varlist tmaxfluctmt tminfluctmt sunfluctmt rainfluctmt {
&nbsp;&nbsp; &nbsp;qui xtmixed `var' ib4.month year || station:, nolog vsquish noheader noretable
&nbsp;&nbsp; &nbsp;qui margins month, atmeans
&nbsp;&nbsp; &nbsp;marginsplot, ti(`var') name(`var'_margins, replace) nodraw
}
gr combine tmaxfluctmt_margins tminfluctmt_margins sunfluctmt_margins rainfluctmt_margins, altshrink nocopies


// changeability/fluctuations across years

// collapse data over years

collapse tdiffmeanmtfluctyr tavgmeanmtfluctyr tmaxmeanmtfluctyr tminmeanmtfluctyr ///
&nbsp;rainmeanmtfluctyr snowmeanmtfluctyr sunmeanmtfluctyr, by(station month)

label define month 1 "Jan" 2 "Feb" 3 "Mar" 4 "Apr" 5 "May" 6 "Jun" 7 "Jul" ///
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;8 "Aug" 9 "Sep" 10 "Oct" 11 "Nov" 12 "Dec"
label value month month

// distribution of yearly fluctuations of sunshine hours
ladder sun
gladder sun 
* nicely normal

// bar graph of sunshine hours

tw bar sunmeanmtfluctyr month&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;/// =
, by(&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp; station, note(" ") rows(2) noiytitle noiytick&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp;&nbsp;&nbsp; ti("Cumulative year-to-year change in monthly sunshine hours", size(medsmall)) ///
&nbsp;&nbsp;&nbsp;&nbsp; subti("6 Swiss weather stations, 1979-2013", size(small))&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp;&nbsp;&nbsp; ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
subtitle(, size(small)) ytitle(" ", size(small)) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
yscale(noline) yti(" ")&nbsp;&nbsp; &nbsp;yla(, labsize(small) labgap(0)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;grid glwidth(vvvthin) glcolor(gs14) glpattern(solid) nogextend)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;/// 
xtitle(" ") xlabel(1(1)12, labsize(vsmall) ang() alt)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
lc(white)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
name(bar_sunmeanmtfluctyr_2, replace)

// multilevel linear regressions of year-to-year sunshine changeability on month
xtmixed sunmeanmtfluctyr ib4.month || station:, nolog vsquish noretable

qui margins month
marginsplot, ti(Cumulative year-to-year change in monthly sunshine hours)&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;subti("6 Swiss weather stations, 1979-2013")&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;yti(" ")&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;yla(0(20)100, grid glw(vvvthin) glc(gs14) glp(solid) nogextend)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;/// 
&nbsp;&nbsp; &nbsp;xti(" ")&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;///
&nbsp;&nbsp; &nbsp;name(sunmeanmtfluctyr_margins, replace)

// check linearity of model
xtmixed sun*fluctyr ib4.month || station:, nolog vsquish noretable
capture drop f r 
qui xtmixed sunmeanmtfluctyr ib4.month || station:, nolog vsquish noretable
predict f, fitted
predict r, residuals
gr tw (sc r f, yline(0, lcolor(cranberry)) title("Residuals vs fitted: final model") subtitle("`e(cmdline)'", size(tiny))) ///
(lowess r f, lcolor(eltblue) lpattern(solid)), name(sc_res_tfitted_xtmixed_t_final, replace) legend(off)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s