This repository holds completed empirical exercises from "Introduction to Econometrics, 4th Edition" by Stock and Watson.
Link to site: Stock and Watson website
This repository implements econometrics exercises from Stock and Watson's textbook, demonstrating key concepts through practical analysis of real-world datasets. Each chapter focuses on different econometric techniques and datasets.
Analyzes the relationship between earnings and height using data from the US National Health Interview Survey (1994). Key concepts:
- Multiple regression analysis
- Omitted variable bias
- Perfect multicollinearity analysis
- Interpretation of regression coefficients
Examines the effect of smoking and other variables on birthweight using data from the National Natality-Mortality Detail File for births in Pennsylvania in 1989. Key concepts:
- Causal inference
- Confidence intervals, robustness
- Ommited variable bias
- Multiple regression analysis
SW-econometrics-exercises/
├── Chapters/
│ ├── Chapter4/
│ │ ├── common-requirements.txt # General requirements
│ │ ├── environment.yml # Conda environment file
│ │ ├── Python code/ # Python implementation
│ │ │ ├── Earnings_and_Height_Python.ipynb
│ │ │ └── requirements.txt # Python-specific requirements
│ │ ├── R code/ # R implementation
│ │ │ ├── Earnings_and_Height_R.ipynb
│ │ │ └── install_R_packages.R
│ │ └── Used data and given exercise/ # Data and instructions
│ │ ├── Earnings and Height Exercise.pdf
│ │ ├── Earnings_and_Height_Description.pdf
│ │ ├── Earnings_and_Height.ods
│ │ ├── Earnings_and_Height.xlsx
│ │ ├── Page 1.png
│ │ └── Page 2.png
│ └── Chapter5/
│ ├── common-requirements.txt # General requirements
│ ├── environment.yml # Conda environment file
│ ├── Python code/ # Python implementation
│ │ ├── Birthweight_and_Smoking_Python.ipynb
│ │ └── requirements.txt # Python-specific requirements
│ ├── R code/ # R implementation
│ │ ├── Birthweight_and_Smoking_R.ipynb
│ │ └── install_R_packages.R
│ └── Used data and given exercise/ # Data and instructions
│ ├── Birthweight_and_Smoking_Exercise.pdf
│ ├── Birthweight_Smoking_Description.pdf
│ ├── birthweight_smoking.ods
│ ├── birthweight_smoking.xlsx
├── config/
│ └── jupyter_notebook_config.py # Jupyter configuration
└── README.md # This documentation
Through these exercises, you will:
- Apply econometric methods to real-world datasets
- Understand how to interpret regression results
- Learn to identify and address common econometric issues
- Compare implementations in both Python and R (R is less detailed, sorry)
Each chapter has its own set of requirements, which can be installed using the provided instructions.
You will need to run the given commands in the respective chapter folders.
But first clone this repository to your local machine using HTTPS or SSH.
- HTTPS:
git clone https://github.com/Aidas-dev/SW-econometrics-exercises.git- SSH:
git clone https://github.com/Aidas-dev/SW-econometrics-exercises.git- Cleanly install (recommended) Mambaconda to system if not already installed:
Mamba installation guide - Switch to the needed chapter folder in terminal (cd command in Linux)
- Create and activate environment using mamba, from the file in specific chapter of the repository:
mamba env create -f environment.yml mamba activate SW-econometrics-'chapter you used'-env - Register R kernel for Jupyter:
Rscript -e "IRkernel::installspec(name = 'SW-econometrics-r', displayname = 'R (SW econometrics)')" - Start Jupyter notebook:
jupyter notebook
- (Optional) setup config file for Jupyter (see below)
Using this method, you don't need to install the specific packages for Python and R.
ChapterX - the chapter you want to use (replace X with the number of the chapter you want to use) Code lines when installing from repository root.
- Have Python and pip installed (https://www.python.org/downloads/)
- Install common requirements:
pip install -r "Chapters/ChapterX/common-requirements.txt"- Apply Jupyter configuration (see below)
- Install requirements:
pip install -r "Chapters/ChapterX/Python \ code/requirements.txt"- Install R (https://cran.r-project.org/)
- Install packages (note escaped space):
Rscript "Chapters/ChapterX/R \ code/install_R_packages.R"- Verify kernel:
IRkernel::installspec(user = FALSE)Configure using either:
- Copy config file:
mkdir -p ~/.jupyter
cp config/jupyter_notebook_config.py ~/.jupyter/- Or use config flag:
jupyter notebook --config=config/jupyter_notebook_config.pyIncludes:
- Automatic output resizing
- Increased rate limits
- Auto-scrolling
- Launch Jupyter:
jupyter notebook- Open either:
- R notebook (
Earnings_and_Height_R.ipynborBirthweight_and_Smoking_R.ipynb) - Python notebook (
Earnings_and_Height_Python.ipynborBirthweight_and_Smoking_Python.ipynb)
- R notebook (
- Follow instructions from the respective exercise PDF
- Scatterplot with horizontal lines (earnings brackets)
- Regression showing:
- Initial positive height coefficient
- Reduced coefficient when controlling for education
- Gender differences in results
- Regression analysis of smoking on birthweight
- Credible interval calculation and robustness
- Interpretation of other variable effects on birthweight
Available in:
- OpenDocument (.ods)
- Excel (.xlsx), problems reading this file so ODS is used instead.
Variables include:
- Chapter 4: age, earnings, education, height, marital status, occupation, race/ethnicity, region, sex, weight
- Chapter 5: birthweight, smoker status, mother's age, education, marital status, race/ethnicity