1.5 The software workflow
Modern econometrics is done with software, and a postgraduate economist is expected to be fluent in at least one package. These notes use R, which is free, runs on every operating system, and records an analysis as a script that anyone can rerun. Every panel marked Software shows commands, the output they actually print, and how to read that output against the theory. Where a command differs in Stata or EViews, the two other packages most used in economics, the equivalent is given at the end of the panel.
A reproducible analysis has a fixed shape whatever the package:
- (1)
- Load the data from a file or a database, never by retyping.
- (2)
- Inspect: dimensions, variable names, summary statistics, plots. Most errors in empirical work are data errors found at this stage or not at all.
- (3)
- Transform: logarithms, differences, deflating by a price index. Do it in the script, so the transformation is recorded.
- (4)
- Estimate and test.
- (5)
- Report, with the script kept alongside the results.
Menu-driven work in Stata or EViews is convenient while exploring. The final analysis should still be a script (a Stata do-file, an EViews program), because a result that cannot be reproduced cannot be checked.
Software 1.5.1 (Loading and inspecting a cross section). LifeCycleSavings is supplied with R.
> data(LifeCycleSavings) > head(LifeCycleSavings, 4) sr pop15 pop75 dpi ddpi Australia 11.43 29.35 2.87 2329.68 2.87 Austria 12.07 23.32 4.41 1507.99 3.93 Belgium 13.17 23.80 4.43 2108.47 3.82 Bolivia 5.75 41.89 1.67 189.13 0.22 > dim(LifeCycleSavings) [1] 50 5 > summary(LifeCycleSavings$sr) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.600 6.970 10.510 9.671 12.617 21.100
Reading the output. The data are a cross section: one row per country, 50 rows, and the row order (alphabetical) carries no meaning. Besides sr and pop15 there are pop75, the percentage aged over 75, dpi, real per capita disposable income in US dollars, and ddpi, its growth rate in percent. The savings rate ranges from \(0.6\%\) to \(21.1\%\). Its mean, \(9.67\), is a little below its median, \(10.51\), a sign of a longer tail on the low side.
Stata: summarize sr (or summarize sr, detail for quartiles). EViews: open the series and choose View \(\to \) Descriptive Statistics, or type sr.stats.
Software 1.5.2 (Correlations and a test of zero correlation). The correlation matrix of all five variables, then a test that one correlation is zero:
> round(cor(LifeCycleSavings), 3) sr pop15 pop75 dpi ddpi sr 1.000 -0.456 0.317 0.220 0.305 pop15 -0.456 1.000 -0.908 -0.756 -0.048 pop75 0.317 -0.908 1.000 0.787 0.025 dpi 0.220 -0.756 0.787 1.000 -0.129 ddpi 0.305 -0.048 0.025 -0.129 1.000 > with(LifeCycleSavings, cor.test(sr, pop15)) Pearson's product-moment correlation data: sr and pop15 t = -3.5453, df = 48, p-value = 0.0008866 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.6513020 -0.2029202 sample estimates: cor -0.4555381
Reading the output. The matrix is symmetric with ones on the diagonal, as Theorem 1.3.2 requires. Savings are negatively correlated with the young-dependant share and positively with the old-age share. That second sign is surprising at first, because the elderly also dissave. The explanation is the very large correlation, \(-0.908\), between pop15 and pop75: countries with many children have few old people. Pairwise correlations cannot separate the two effects, and that is what multiple regression is for.
The test in the second command is of \(H_0\colon \rho = 0\). Its statistic is \[ t = \frac {r\sqrt {n-2}}{\sqrt {1 - r^2}} = \frac {-0.4555\sqrt {48}}{\sqrt {1 - 0.2075}} = -3.545 , \] which has a \(t_{n-2}\) distribution when \(\rho = 0\) and the observations are independent draws from a bivariate normal distribution. It is the same statistic as the \(t\) test on the slope of a two-variable regression. With \(p = 0.0009\) the hypothesis of no correlation is firmly rejected.
The confidence interval is not \(r \pm 1.96\,\mathrm {se}\). It uses Fisher’s transformation \(z = \tanh ^{-1} r\), which is approximately normal with variance \(\frac {1}{n-3}\). Here \(\tanh ^{-1}(-0.4555) = -0.4917\), so the interval for \(\tanh ^{-1}\rho \) is \(-0.4917 \pm 1.96/\sqrt {47} = (-0.7776, -0.2058)\), and applying \(\tanh \) to both ends gives the printed \((-0.651, -0.203)\). The interval is asymmetric about \(r\) because the correlation is bounded by \(\pm 1\). Why the transformation works is an application of the delta method (Example 4.3.5).
Stata: correlate sr pop15 pop75 dpi ddpi, and pwcorr sr pop15, sig for the \(p\)-value. EViews: select the series, open them as a group and choose View \(\to \) Covariance Analysis, ticking Correlation and t-statistic.
Software 1.5.3 (A time series). The number of mobile telephone subscribers in Zambia, in thousands, for 2010–2014:
> subs <- ts(c(38.1, 80.0, 170.4, 354.5, 744.4), start = 2010) > round(diff(log(subs)), 3) Time Series: Start = 2011 End = 2014 Frequency = 1 [1] 0.742 0.756 0.733 0.742
Reading the output. ts attaches dates, so R knows the order matters. The first difference of the logarithm, \(\log Y_t - \log Y_{t-1} = \log (Y_t/Y_{t-1})\), is the growth rate in continuous terms. It is remarkably steady, close to \(0.74\) every year, which says the series is growing at a constant proportional rate. A plot of \(\log Y_t\) against \(t\) is then a straight line, and fitting that line is the constant growth curve, the subject of the section on functional form, where these data are analysed fully.
Stata: tsset year, then generate g = D.ln_subs. EViews: series g = dlog(subs).
Questions on this section
Stuck on something here? Ask below and it stays attached to this topic.