Skip to content

Commit c6d97c1

Browse files
authored
Merge pull request #80 from pedrovma/master
Updating the Fixed Effects Panel notebook
2 parents 7b2bd72 + d4b8b0a commit c6d97c1

File tree

1 file changed

+66
-67
lines changed

1 file changed

+66
-67
lines changed

notebooks/Panel_FE_example.ipynb

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,69 +14,17 @@
1414
{
1515
"cell_type": "code",
1616
"execution_count": 1,
17-
"metadata": {
18-
"ExecuteTime": {
19-
"end_time": "2021-01-04T16:36:50.179530Z",
20-
"start_time": "2021-01-04T16:36:50.121692Z"
21-
}
22-
},
23-
"outputs": [
24-
{
25-
"name": "stdout",
26-
"output_type": "stream",
27-
"text": [
28-
"Last updated: 2021-01-04T11:36:50.162976-05:00\n",
29-
"\n",
30-
"Python implementation: CPython\n",
31-
"Python version : 3.8.6\n",
32-
"IPython version : 7.19.0\n",
33-
"\n",
34-
"Compiler : Clang 11.0.0 \n",
35-
"OS : Darwin\n",
36-
"Release : 20.2.0\n",
37-
"Machine : x86_64\n",
38-
"Processor : i386\n",
39-
"CPU cores : 8\n",
40-
"Architecture: 64bit\n",
41-
"\n"
42-
]
43-
}
44-
],
45-
"source": [
46-
"%load_ext watermark\n",
47-
"%watermark"
48-
]
49-
},
50-
{
51-
"cell_type": "code",
52-
"execution_count": 2,
5317
"metadata": {
5418
"ExecuteTime": {
5519
"end_time": "2021-01-04T16:36:53.158014Z",
5620
"start_time": "2021-01-04T16:36:50.182287Z"
5721
}
5822
},
59-
"outputs": [
60-
{
61-
"name": "stdout",
62-
"output_type": "stream",
63-
"text": [
64-
"Watermark: 2.1.0\n",
65-
"\n",
66-
"spreg : 1.2.0.post1\n",
67-
"libpysal: 4.3.0\n",
68-
"numpy : 1.19.4\n",
69-
"\n"
70-
]
71-
}
72-
],
23+
"outputs": [],
7324
"source": [
7425
"import numpy\n",
7526
"import libpysal\n",
76-
"import spreg\n",
77-
"\n",
78-
"%watermark -w\n",
79-
"%watermark -iv"
27+
"import spreg"
8028
]
8129
},
8230
{
@@ -94,7 +42,7 @@
9442
},
9543
{
9644
"cell_type": "code",
97-
"execution_count": 3,
45+
"execution_count": 2,
9846
"metadata": {
9947
"ExecuteTime": {
10048
"end_time": "2021-01-04T16:36:53.489678Z",
@@ -138,7 +86,7 @@
13886
},
13987
{
14088
"cell_type": "code",
141-
"execution_count": 4,
89+
"execution_count": null,
14290
"metadata": {
14391
"ExecuteTime": {
14492
"end_time": "2021-01-04T16:36:59.736302Z",
@@ -147,14 +95,12 @@
14795
},
14896
"outputs": [],
14997
"source": [
150-
"fe_lag = spreg.Panel_FE_Lag(\n",
151-
" y, x, w, name_y=name_y, name_x=name_x, name_ds=\"NAT\"\n",
152-
")"
98+
"fe_lag = spreg.Panel_FE_Lag(y, x, w, name_y=name_y, name_x=name_x, name_ds=\"NAT\")"
15399
]
154100
},
155101
{
156102
"cell_type": "code",
157-
"execution_count": 5,
103+
"execution_count": 4,
158104
"metadata": {
159105
"ExecuteTime": {
160106
"end_time": "2021-01-04T16:36:59.741882Z",
@@ -201,7 +147,7 @@
201147
},
202148
{
203149
"cell_type": "code",
204-
"execution_count": 6,
150+
"execution_count": 5,
205151
"metadata": {
206152
"ExecuteTime": {
207153
"end_time": "2021-01-04T16:36:59.753663Z",
@@ -217,7 +163,7 @@
217163
" [ 0.1903]])"
218164
]
219165
},
220-
"execution_count": 6,
166+
"execution_count": 5,
221167
"metadata": {},
222168
"output_type": "execute_result"
223169
}
@@ -226,6 +172,59 @@
226172
"numpy.around(fe_lag.betas, decimals=4)"
227173
]
228174
},
175+
{
176+
"cell_type": "markdown",
177+
"metadata": {},
178+
"source": [
179+
"### Data can also be in 'long' format:"
180+
]
181+
},
182+
{
183+
"cell_type": "code",
184+
"execution_count": 6,
185+
"metadata": {},
186+
"outputs": [
187+
{
188+
"name": "stdout",
189+
"output_type": "stream",
190+
"text": [
191+
"REGRESSION\n",
192+
"----------\n",
193+
"SUMMARY OF OUTPUT: MAXIMUM LIKELIHOOD SPATIAL LAG PANEL - FIXED EFFECTS\n",
194+
"-----------------------------------------------------------------------\n",
195+
"Data set : NAT\n",
196+
"Weights matrix : unknown\n",
197+
"Dependent Variable : HR Number of Observations: 9255\n",
198+
"Mean dependent var : 0.0000 Number of Variables : 3\n",
199+
"S.D. dependent var : 3.9228 Degrees of Freedom : 9252\n",
200+
"Pseudo R-squared : 0.0319\n",
201+
"Spatial Pseudo R-squared: 0.0079\n",
202+
"Sigma-square ML : 14.935 Log likelihood : -67936.533\n",
203+
"S.E of regression : 3.865 Akaike info criterion : 135879.066\n",
204+
" Schwarz criterion : 135900.465\n",
205+
"\n",
206+
"------------------------------------------------------------------------------------\n",
207+
" Variable Coefficient Std.Error z-Statistic Probability\n",
208+
"------------------------------------------------------------------------------------\n",
209+
" RD 0.8005886 0.1614474 4.9588189 0.0000007\n",
210+
" PS -2.6003523 0.4935486 -5.2686851 0.0000001\n",
211+
" W_HR 0.1903043 0.0159991 11.8947008 0.0000000\n",
212+
"------------------------------------------------------------------------------------\n",
213+
"Warning: Assuming panel is in long format.\n",
214+
"y[0:N] refers to T0, y[N+1:2N] refers to T1, etc.\n",
215+
"x[0:N] refers to T0, x[N+1:2N] refers to T1, etc.\n",
216+
"================================ END OF REPORT =====================================\n"
217+
]
218+
}
219+
],
220+
"source": [
221+
"y_long = y.reshape((y.shape[0]*y.shape[1],1), order='F')\n",
222+
"x_long = x.reshape((x.shape[0]*3,2), order='F')\n",
223+
"\n",
224+
"fe_lag_long = spreg.Panel_FE_Lag(y_long, x_long, w, name_y=name_y, name_x=name_x, name_ds=\"NAT\")\n",
225+
"print(fe_lag_long.summary)"
226+
]
227+
},
229228
{
230229
"cell_type": "markdown",
231230
"metadata": {},
@@ -295,8 +294,8 @@
295294
" Variable Coefficient Std.Error z-Statistic Probability\n",
296295
"------------------------------------------------------------------------------------\n",
297296
" RD 0.8697923 0.1718029 5.0627323 0.0000004\n",
298-
" PS -2.9660674 0.5444784 -5.4475397 0.0000001\n",
299-
" lambda 0.1943460 0.0160253 12.1274222 0.0000000\n",
297+
" PS -2.9660674 0.5444783 -5.4475397 0.0000001\n",
298+
" lambda 0.1943460 0.0160253 12.1274197 0.0000000\n",
300299
"------------------------------------------------------------------------------------\n",
301300
"Warning: Assuming panel is in wide format.\n",
302301
"y[:, 0] refers to T0, y[:, 1] refers to T1, etc.\n",
@@ -346,9 +345,9 @@
346345
],
347346
"metadata": {
348347
"kernelspec": {
349-
"display_name": "Python [conda env:py38_spreg]",
348+
"display_name": "Python [conda env:myenv] *",
350349
"language": "python",
351-
"name": "conda-env-py38_spreg-py"
350+
"name": "conda-env-myenv-py"
352351
},
353352
"language_info": {
354353
"codemirror_mode": {
@@ -360,7 +359,7 @@
360359
"name": "python",
361360
"nbconvert_exporter": "python",
362361
"pygments_lexer": "ipython3",
363-
"version": "3.8.6"
362+
"version": "3.6.10"
364363
}
365364
},
366365
"nbformat": 4,

0 commit comments

Comments
 (0)