|
47 | 47 | "metadata": {},
|
48 | 48 | "outputs": [],
|
49 | 49 | "source": [
|
50 |
| - "mi_data = data.set_index([\"fcode\", \"year\"])\n", |
| 50 | + "orig_mi_data = data.set_index([\"fcode\", \"year\"])\n", |
| 51 | + "# Subset to the relevant columns and drop missing to avoid warnings\n", |
| 52 | + "mi_data = orig_mi_data[[\"lscrap\",\"hrsemp\"]]\n", |
| 53 | + "mi_data = mi_data.dropna(axis=0, how=\"any\")\n", |
| 54 | + "\n", |
51 | 55 | "print(mi_data.head())"
|
52 | 56 | ]
|
53 | 57 | },
|
|
88 | 92 | "source": [
|
89 | 93 | "import numpy as np\n",
|
90 | 94 | "\n",
|
91 |
| - "np_data = np.asarray(mi_data)\n", |
92 |
| - "np_lscrap = np_data[:, mi_data.columns.get_loc(\"lscrap\")]\n", |
93 |
| - "np_hrsemp = np_data[:, mi_data.columns.get_loc(\"hrsemp\")]\n", |
| 95 | + "np_data = np.asarray(orig_mi_data)\n", |
| 96 | + "np_lscrap = np_data[:, orig_mi_data.columns.get_loc(\"lscrap\")]\n", |
| 97 | + "np_hrsemp = np_data[:, orig_mi_data.columns.get_loc(\"hrsemp\")]\n", |
94 | 98 | "nentity = mi_data.index.levels[0].shape[0]\n",
|
95 | 99 | "ntime = mi_data.index.levels[1].shape[0]\n",
|
96 | 100 | "np_lscrap = np_lscrap.reshape((nentity, ntime)).T\n",
|
|
104 | 108 | "metadata": {},
|
105 | 109 | "outputs": [],
|
106 | 110 | "source": [
|
| 111 | + "# Warnings are inevitable when using NumPy with missing data\n", |
| 112 | + "# since the arrays must be rectangular, and not ragged\n", |
107 | 113 | "res = PanelOLS(np_lscrap, np_hrsemp, entity_effects=True).fit()\n",
|
108 | 114 | "print(res)"
|
109 | 115 | ]
|
|
224 | 230 | "name": "python",
|
225 | 231 | "nbconvert_exporter": "python",
|
226 | 232 | "pygments_lexer": "ipython3",
|
227 |
| - "version": "3.12.0" |
| 233 | + "version": "3.10.12" |
228 | 234 | },
|
229 | 235 | "pycharm": {
|
230 | 236 | "stem_cell": {
|
|
0 commit comments