Exercise 11.2: Drawing frmm standard distributions # Sample size n1 <- 10L n2 <- 100L n3 <- 100000L # We use integers as indicated by the "L" at the end of the number. # This only makes the results look nicer # Reset random number generator for reproducibilty set.seed(123456) Uniform The standard specification of R’s random number generator (RNG) runif is min = 0 and max = 1, which is exactly what we need.
As international trade has become increasingly fragmented over the past decades the analysis of global value chains (GVC) has gained popularity in economic research. This post reproduces Timmer et al. (2015), who introduce the world input-output database (WIOD) and present basic concepts of GVC analysis.
Data Timmer et al. (2015) use the 2013 vintage of the world input-output database (WIOD). The following code downloads the data from the project’s website, unzips it and loads the resulting STATA file into R using the readstata13 package.
This section is based on Chan et al. (2019). Bayesian econometric methods (2nded.). The following links contain examples in the main text of the book and use R to estimate the models.
Chapter 11: Monte Carlo Integration
Chapter 18: State Space and Unobserved Components Models
Chapter 20: Multivariate Time Series Methods
library(wooldridge) Example 11.4 For this regression the lagged values of return are already contained in the dataset. Thus, we do not have to calculated them ourselves and can simply run the regression.
data("nyse") lm.11.4 <- lm(return ~ return_1, data = nyse) summary(lm.11.4) ## ## Call: ## lm(formula = return ~ return_1, data = nyse) ## ## Residuals: ## Min 1Q Median 3Q Max ## -15.261 -1.302 0.098 1.316 8.065 ## ## Coefficients: ## Estimate Std.
In R the function for basic linear regression models is lm, which is short for linear model. Its first argument is a formula of the regression model, which has the form y ~ a. The tilde between y and a indicates that y is the dependent variable and a is the explanatory variable. It is also possible to add a further explanatory variable - for example b - to the regression by adding a plus sign followed by the the name of the additional variable to the formula.
This section is based on Wooldridge, J.M. (2013). Introductory econometrics: A modern approach (5thed.). The following links contain examples in the main text of the book and use R to estimate the models. Alternatively, Heiss, F. (2016) Using R for Introductory Econometrics is a standalone textbook, which covers the same topics as Wooldridge (2013) and provides an introduction to R as well.
The data sets are from the wooldridge package, which is a collection of all data sets used in the Wooldridge textbook.
Get the data The data set can be downloaded from the Journal of Applied Econometrics Data Archive.
download.file("http://qed.econ.queensu.ca/jae/1997-v12.3/cincera/mc-data.zip", destfile = "1997_cincera_data.zip") unzip("1997_cincera_data.zip") data <- read.delim("data.mc", header = FALSE) names(data) <- c("fi", "s", "g", "p83", "p84", "p85", "p86", "p87", "p88", "p89", "p90", "p91", "lr83", "lr84", "lr85", "lr86", "lr87", "lr88", "lr89", "lr90", "lr91", "ls83", "ls84", "ls85", "ls86", "ls87", "ls88", "ls89", "ls90", "ls91") p <- matrix(as.matrix(data[, c("p83", "p84", "p85", "p86", "p87", "p88", "p89", "p90", "p91")])) k <- matrix(as.
library(wooldridge) In order to estimate panel data models, I use the plm function from the plm package. The intuition behind its structure is similar to the ordinary linear model, except that it allows you to specify the panel’s group and time variables and the effects model.
Example 14.1 Similar to the lm function, you can specify your model’s equation and the sample. Since you want to use panel data methods for you estimation, you also have to specify which variables in your sample contain the information used to distinguish different groups and which variable contains the time measurement.
Below you find the script for all examples in chapter 3 of Wooldridge (2013). The only difference to the last chapter is how to use multiple independent variables in the lm function. This is easily achieved by separating each exogenous variable that should enter the model with a plus sign, e.g. lm(colGPA ~ hsGPA + ACT).
The other commands that appear new are quite helpful and you should take a minute to think about them:
Chapter 6 in Wooldridge (2013) deals with some more issues that might have an impact on your estimates. Among these are a change in the scale of your variables, so-called beta-factors and the interpretation of variables that appear together with their squared values, i.e. interaction terms.
Before you start, set your working directory, load the foreign library and download the data we are going to use in this chapter.
library(wooldridge) Estimating dummy variables that reflect qualitative information works quite the same way in R as it does with quantitative variables. You just add it as an independent variable into the formula of the model.
# Example 7.1 data("wage1") lm.7.1.1 <- lm(wage ~ female + educ + exper + tenure, data = wage1) summary(lm.7.1.1) ## ## Call: ## lm(formula = wage ~ female + educ + exper + tenure, data = wage1) ## ## Residuals: ## Min 1Q Median 3Q Max ## -7.