Example: marketing

Principles of Econometrics with R - Bookdown

Principles of Econometrics with R. Constantin Colonescu 2016-09-01. 2. Contents . 5. 1 Introduction 7. The RStudio Screen .. 8. How to Open a Data File .. 9. Creating Graphs .. 10. An R Cheat Sheet .. 11. 2 The Simple Linear Regression Model 13. The General Model .. 13. Example: Food Expenditure versus Income .. 15. Estimating a Linear Regression .. 15. Prediction with the Linear Regression Model .. 18. Repeated Samples to Assess Regression Coefficients .. 19. Estimated Variances and Covariance of Regression Coefficients .. 20. Non-Linear Relationships .. 20. Using Indicator Variables in a Regression .. 24. Monte Carlo Simulation .. 25. 3 Interval Estimation and Hypothesis Testing 29. The Estimated Distribution of Regression Coefficients.

Sep 01, 2016 · 1.2. HOW TO OPEN A DATA FILE 11 1.1.1 TheScript,ordata view window HereareafewtipsforwritingandexecutingscriptintheScriptwindow ...

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Principles of Econometrics with R - Bookdown

1 Principles of Econometrics with R. Constantin Colonescu 2016-09-01. 2. Contents . 5. 1 Introduction 7. The RStudio Screen .. 8. How to Open a Data File .. 9. Creating Graphs .. 10. An R Cheat Sheet .. 11. 2 The Simple Linear Regression Model 13. The General Model .. 13. Example: Food Expenditure versus Income .. 15. Estimating a Linear Regression .. 15. Prediction with the Linear Regression Model .. 18. Repeated Samples to Assess Regression Coefficients .. 19. Estimated Variances and Covariance of Regression Coefficients .. 20. Non-Linear Relationships .. 20. Using Indicator Variables in a Regression .. 24. Monte Carlo Simulation .. 25. 3 Interval Estimation and Hypothesis Testing 29. The Estimated Distribution of Regression Coefficients.

2 29. Confidence Interval in General .. 30. Example: Confidence Intervals in the food Model .. 31. Confidence Intervals in Repeated Samples .. 32. Hypothesis Tests .. 33. The p-Value .. 38. Testing Linear Combinations of Parameters .. 39. 4 Prediction, R-squared, and Modeling 43. Forecasting (Predicting a Particular Value) .. 43. Goodness-of-Fit .. 47. Linear-Log Models .. 49. 3. 4 CONTENTS. Residuals and Diagnostics .. 51. Polynomial Models .. 55. Log-Linear Models .. 56. The Log-Log Model .. 61. 5 The Multiple Regression Model 65. The General Model .. 65. Example: Big Andy's Hamburger Sales .. 66. Interval Estimation in Multiple Regression .. 71. Hypothesis Testing in Multiple Regression .. 73. Polynomial Regression Models .. 76. Interaction Terms in Linear Regression.

3 78. Goodness-of-Fit in Multiple Regression .. 81. 6 Further Inference in Multiple Regression 83. Joint Hypotheses and the F-statistic .. 83. Testing Simultaneous Hypotheses .. 84. Omitted Variable Bias .. 88. Irrelevant Variables .. 90. Model Selection Criteria .. 91. Collinearity .. 94. Prediction and Forecasting .. 96. 7 Using Indicator Variables 97. Factor Variables .. 97. Examples .. 98. Comparing Two Regressions: the Chow Test .. 101. Indicator Variables in Log-Linear Models .. 103. The Linear Probability Model .. 103. Treatment Effects .. 105. The Difference-in-Differences Estimator .. 109. Using Panel Data .. 112. R Practicum .. 115. 8 Heteroskedasticity 119. Spotting Heteroskedasticity in Scatter Plots .. 120. Heteroskedasticity Tests.

4 121. Heteroskedasticity-Consistent Standard Errors .. 125. GLS: Known Form of Variance .. 127. Grouped Data .. 129. GLS: Unknown Form of Variance .. 131. Heteroskedasticity in the Linear Probability Model .. 133. CONTENTS 5. 9 Time-Series: Stationary Variables 135. An Overview of Time Series Tools in R .. 136. Finite Distributed Lags .. 136. Serial Correlation .. 138. Estimation with Serially Correlated Errors .. 145. Nonlinear Least Squares Estimation .. 147. A More General Model .. 149. Autoregressive Models .. 150. Forecasting .. 152. Multiplier Analysis .. 156. 10 Random Regressors 159. The Instrumental Variables (IV) Method .. 159. Specification Tests .. 163. 11 Simultaneous Equations Models 167. 12 Time Series: Nonstationarity 175.

5 AR(1), the First-Order Autoregressive Model .. 176. Spurious Regression .. 179. Unit Root Tests for Stationarity .. 182. Cointegration .. 188. The Error Correction Model .. 189. 13 VEC and VAR Models 193. VAR and VEC Models .. 193. Estimating a VEC Model .. 194. Estimating a VAR Model .. 197. Impulse Responses and Variance Decompositions .. 202. 14 Time-Varying Volatility and ARCH Models 205. The ARCH Model .. 206. The GARCH Model .. 210. 15 Panel Data Models 215. Organizing the Data as a Panel .. 216. The Pooled Model .. 216. The Fixed Effects Model .. 218. The Random Effects Model .. 221. Grunfeld's Investment Example .. 224. 16 Qualitative and LDV Models 231. The Linear Probability Model .. 231. The Probit Model .. 232. 6 CONTENTS.

6 The Transportation Example .. 232. The Logit Model for Binary Choice .. 234. Multinomial Logit .. 237. The Conditional Logit Model .. 238. Ordered Choice Models .. 241. Models for Count Data .. 242. The Tobit, or Censored Data Model .. 243. Heckit, or Sample Selection Model .. 245. References 249.. 7. 8 CONTENTS. Chapter 1. Introduction rm(list=ls()) # Caution: this clears the Environment library( Bookdown ). library(PoEdata). library(knitr). library(xtable). library(printr). library(stargazer). library(rmarkdown). Although this manual is self-contained, it can be used as a supplementary resource for the Principles of Econometrics textbook by Carter Hill, William Griffiths and Guay Lim, 4-th edition (Hill, Griffiths, and Lim 2011). The following list gives some of the R packages that are used in this book more frequently: devtools (Wickham and Chang 2016).

7 PoEdata (Colonescu 2016). knitr (Xie 2016b). Bookdown (Xie 2016a). xtable (Dahl 2016). printr (Xie 2014). stargazer (Hlavac 2015). rmarkdown (Allaire et al. 2016). The function install_git from the package devtools installs packages such as PoEdata from the GitHub web site. Here is the code that installs devtools and Bookdown : 9. 10 CHAPTER 1. INTRODUCTION. Figure : The four quadrants of an RStudio screen ("devtools"). devtools::install_git(. " "). The computing environment for using R (R Development Core Team 2008) is RStudio (RStudio Team 2015). You need to install on your computer the following resources: R ( ). RStudio ( ). PoEdata package ( ). This brief introduction to R does not intend to be exhaustive, but to cover the minimum material used in this book.

8 Please refer to the R documentation and to many other resuorces for additional information. For beginners, I would recommend (Lander 2013). The RStudio Screen A typical RStudio Screen is divided in four quadrants, as Figure shows. The NW. quadrant is for writing your script and for viewing data. knitr::include_graphics(. "01-intro_ "). HOW TO OPEN A DATA FILE 11. The Script, or data view window Here are a few tips for writing and executing script in the Script window: You may start your script with a comment showing a title and a brief description of what the script does. A comment line starts with the hash character (#). Comments can be inserted anywhere in the script, even in line with code, but what follows the hash character to the end of the line will be disregarded by R.

9 Code lines may be continued on the next line with no special character to announce a line continuation. However, code will be continued on the next line only if the previous line ends in a way that requires continuation, for instance with a comma or unclosed brackets. When you want to run a certain line of code, place the cursor anywhere on the line and press Ctrl+Enter; if you want to run a sequence of several code lines, select the respective sequence and press Ctrl+Enter. The console, or output window While it is always advisable to work in the script mode because it can be saved and re-used for different data, sometimes we need to run commands that are out of the script context. Such commands can be typed at the bottom of the console at the sign >.

10 Pressing Enter executes such a command, and the up and down arrows allow re-activating and editing older lines of code that had been previously typed into the console. How to Open a Data File To open a data file for the Principles of Econometrics textbook, (Hill, Griffiths, and Lim 2011), first check if the devtools package is installed. If it is not, run the code ("devtools") in the console. devtools::install_git(. " "). library(PoEdata) # Makes datasets ready to use Now, we can load and inspect a particular dataset, for example andy. When the dataset is available, it sould show in the Environment window (look up and right). library(PoEdata). data("andy") # makes the dataset "andy" ready to use ?andy # shows information about the dataset 12 CHAPTER 1.


Related search queries