DATA SCIENCE PROJECT INSTRUCTIONS
{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "9366171b", "metadata": {}, "outputs": [], "source": [ "# Import packages that will be used in this program\n", "import pandas as pd\n", "from linearmodels import PanelOLS\n", "import statsmodels.api as sm" ] }, { "cell_type": "code", "execution_count": null, "id": "2b5912ae", "metadata": {}, "outputs": [], "source": [ "# Load the csv data file. You need to change the directory to where your data file is located\n", "df = pd.read_csv('C:\\\\Users\\\\85292\\\\Desktop\\\\data_wdi.csv')" ] }, { "cell_type": "code", "execution_count": null, "id": "17a78cfc", "metadata": { "scrolled": true }, "outputs": [], "source": [ "# Set the country id and year as indices, that is to set the dataframe as a panel dataset\n", "df = df.set_index(['code', 'year'])" ] }, { "cell_type": "code", "execution_count": null, "id": "f9e42e47", "metadata": {}, "outputs": [], "source": [ "# See a snapshot of the dataset\n", "display(df)" ] }, { "cell_type": "code", "execution_count": null, "id": "7e2ecb52", "metadata": {}, "outputs": [], "source": [ "# Enter the independent variables\n", "indep_vars = ['ms_growth', 'pop', 'cab_gdp']" ] }, { "cell_type": "code", "execution_count": null, "id": "dd7492e4", "metadata": {}, "outputs": [], "source": [ "# Add a constant to the independent variable\n", "indep = sm.add_constant(df[indep_vars])" ] }, { "cell_type": "code", "execution_count": null, "id": "e23d253a", "metadata": {}, "outputs": [], "source": [ "# Set a fixed-effect model\n", "mod = PanelOLS(df.inflat_cpi, indep, entity_effects=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "1bc12c00", "metadata": {}, "outputs": [], "source": [ "# Estiamte the model\n", "results = mod.fit()" ] }, { "cell_type": "code", "execution_count": null, "id": "19856ce4", "metadata": {}, "outputs": [], "source": [ "print(results)" ] }, { "cell_type": "code", "execution_count": null, "id": "395fc62f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }