Skip to content

Commit 5fd5a1a

Browse files
committed
Minor modification to lasso_cont
1 parent 2807543 commit 5fd5a1a

2 files changed

Lines changed: 445 additions & 0 deletions

File tree

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"%%capture\n",
10+
"import stata_setup, os\n",
11+
"if os.name == 'nt':\n",
12+
" stata_setup.config('C:/Program Files/Stata17/','mp')\n",
13+
"else:\n",
14+
" stata_setup.config('/usr/local/stata17','mp')"
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"## Data Preparation"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 2,
27+
"metadata": {},
28+
"outputs": [
29+
{
30+
"name": "stdout",
31+
"output_type": "stream",
32+
"text": [
33+
"\n"
34+
]
35+
}
36+
],
37+
"source": [
38+
"%%stata -qui\n",
39+
"\n",
40+
"use \"../data/data\", clear\n",
41+
"\n",
42+
"quietly tabulate year, generate(y_)\n",
43+
"quietly tabulate cluster, generate(c_)\n",
44+
"\n",
45+
"* Generate the Flesch-Kincaid Grade Level indicator\n",
46+
"summarize flesch_kincaid_grade_level, detail\n",
47+
"local cutoff = r(p90)\n",
48+
"gen int FKG_01 = (flesch_kincaid_grade_level >= `cutoff')\n",
49+
"\n",
50+
"* Generate the excess number of sentences count\n",
51+
"summarize num_sentences, detail\n",
52+
"local cutoff_sentences = r(p5)\n",
53+
"gen int excess_sentences = num_sentences - `cutoff_sentences'\n",
54+
"replace excess_sentences = 0 if excess_sentences < 0\n",
55+
"\n",
56+
"local journals ecm jpe qje res //AER based category\n",
57+
"\n",
58+
"local jel_imp a_imp b_imp c_imp e_imp f_imp g_imp h_imp i_imp j_imp k_imp /// \n",
59+
"\t\tl_imp m_imp n_imp o_imp p_imp q_imp r_imp y_imp z_imp // D JEL based case\n",
60+
"\n",
61+
"\n",
62+
"#delimit ;\n",
63+
"vl set log_num_authors log_num_pages both_genders prop_women\n",
64+
" `journals' `jel_imp' y_2-y_20 c_2-c_215 jel_flag\n",
65+
" , dummy clear nonotes;\n",
66+
"vl create fe = vldummy - (both_genders jel_flag);\n",
67+
"vl substitute mfe = i.fe;\n",
68+
"vl create controls = vlcontinuous - (prop_women);\n",
69+
"vl create controls_dummy = (both_genders jel_flag);\n",
70+
"vl substitute baseline = i.controls_dummy controls;\n",
71+
"vl rebuild;\n",
72+
"#delimit cr"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {},
78+
"source": [
79+
"# Elastic Net - Logistic"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": 3,
85+
"metadata": {},
86+
"outputs": [
87+
{
88+
"name": "stdout",
89+
"output_type": "stream",
90+
"text": [
91+
"\n"
92+
]
93+
}
94+
],
95+
"source": [
96+
"%%stata -qui -eret steret\n",
97+
"#delimit ;\n",
98+
"elasticnet logit FKG_01 prop_women $baseline $mfe, alpha(0.99) lambda(0.02) nolog;\n",
99+
"#delimit cr"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": 4,
105+
"metadata": {},
106+
"outputs": [
107+
{
108+
"name": "stdout",
109+
"output_type": "stream",
110+
"text": [
111+
"------------------------------------------------------------------------------\n",
112+
" FKG_01 | Coefficient\n",
113+
"-------------+----------------------------------------------------------------\n",
114+
" c_4 |\n",
115+
" 0 | -.3811678\n",
116+
" 1 | .3843454\n",
117+
" |\n",
118+
" _cons | -1.816232\n",
119+
"------------------------------------------------------------------------------\n"
120+
]
121+
}
122+
],
123+
"source": [
124+
"%stata ereturn display"
125+
]
126+
},
127+
{
128+
"cell_type": "markdown",
129+
"metadata": {},
130+
"source": [
131+
"# Elastic Net - Poisson"
132+
]
133+
},
134+
{
135+
"cell_type": "code",
136+
"execution_count": 5,
137+
"metadata": {},
138+
"outputs": [
139+
{
140+
"name": "stdout",
141+
"output_type": "stream",
142+
"text": [
143+
"\n"
144+
]
145+
}
146+
],
147+
"source": [
148+
"%%stata -qui -eret steret\n",
149+
"#delimit ;\n",
150+
"elasticnet poisson excess_sentences prop_women $baseline $mfe, alpha(0.7) lambda(.1) nolog;\n",
151+
"#delimit cr"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": 6,
157+
"metadata": {},
158+
"outputs": [
159+
{
160+
"name": "stdout",
161+
"output_type": "stream",
162+
"text": [
163+
"------------------------------------------------------------------------------\n",
164+
"excess_sen~s | Coefficient\n",
165+
"-------------+----------------------------------------------------------------\n",
166+
"log_num_pa~s | .3588161\n",
167+
" |\n",
168+
" ecm |\n",
169+
" 0 | -.1451147\n",
170+
" 1 | .1451147\n",
171+
" |\n",
172+
" qje |\n",
173+
" 0 | -.0868885\n",
174+
" 1 | .0868885\n",
175+
" |\n",
176+
" res |\n",
177+
" 0 | -.1660911\n",
178+
" 1 | .1660911\n",
179+
" |\n",
180+
" c_imp |\n",
181+
" 0 | -.0183949\n",
182+
" 1 | .0183949\n",
183+
" |\n",
184+
" c_86 |\n",
185+
" 0 | -.1177174\n",
186+
" 1 | .1177467\n",
187+
" |\n",
188+
" c_114 |\n",
189+
" 0 | -.2093475\n",
190+
" 1 | .2098763\n",
191+
" |\n",
192+
" c_136 |\n",
193+
" 0 | -.5765329\n",
194+
" 1 | .5765334\n",
195+
" |\n",
196+
" c_142 |\n",
197+
" 0 | -.0506581\n",
198+
" 1 | .0506593\n",
199+
" |\n",
200+
" c_174 |\n",
201+
" 0 | -.0596673\n",
202+
" 1 | .0596695\n",
203+
" |\n",
204+
" _cons | .9339063\n",
205+
"------------------------------------------------------------------------------\n"
206+
]
207+
}
208+
],
209+
"source": [
210+
"%stata ereturn display"
211+
]
212+
}
213+
],
214+
"metadata": {
215+
"kernelspec": {
216+
"display_name": "Python 3",
217+
"language": "python",
218+
"name": "python3"
219+
},
220+
"language_info": {
221+
"codemirror_mode": {
222+
"name": "ipython",
223+
"version": 3
224+
},
225+
"file_extension": ".py",
226+
"mimetype": "text/x-python",
227+
"name": "python",
228+
"nbconvert_exporter": "python",
229+
"pygments_lexer": "ipython3",
230+
"version": "3.12.3"
231+
}
232+
},
233+
"nbformat": 4,
234+
"nbformat_minor": 2
235+
}

0 commit comments

Comments
 (0)