Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
thornoe committed Feb 15, 2023
1 parent 14d56dd commit 23cccd5
Show file tree
Hide file tree
Showing 28 changed files with 105 additions and 58 deletions.
58 changes: 37 additions & 21 deletions Example_Stata_LaTeX.do
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
* MIT LICENSE: Copyright (c) 2023 Thor Donsby Noe (give credit; no liability)
********************************************************************************
/* Installations
ssc install bcuse // access Wooldridge datasets for the examples below
ssc install estout // export tables to Excel, Word, or LaTeX
ssc install bcuse // access Wooldridge datasets for the examples below
ssc install estout // export tables to Excel, Word, or LaTeX
ssc install extremes // list extreme observations for a variable
*/

* Change directory to the folder with your data files (redundant for bcuse)
Expand Down Expand Up @@ -60,15 +61,16 @@ label variable trend "Time trend" // covering year t in {0,1,2}
********************************************************************************
* DESCRIPTIVE ANALYSIS (of panel data)
********************************************************************************
* Take a first look at the data
* Take a first look at the data (by year)
xtdescribe // balanced panel of 157 firms observed each year 1987-89
sort year fcode // sort data by year and firm (required for "by year" command)
by year: tab grant if scrap!=. // scrap only recorded for 54 of the 157 firms
by year: sum scrap grant grant_1 if scrap!=. // scrap rate is reduced each year
correlate scrap year // scrap rate has a negative correlation with time
correlate scrap grant_lead grant_lead2 if d88==0 & d89==0 // is treatment assignment random?
bysort year: tab grant if scrap!=. // scrap only recorded for 54 of the 157 firms
/* Of the 54 firms for which scrap rate is recorded,
19 firms (35.2 %) received a grant in 1988,
and another 10 firms (18.5 %) received a grant in 1989.
*/
bysort year: sum scrap grant grant_1 if scrap!=. // mean scrap rate decreases each year

* Take a closer look at variation in the reduced sample where scrap is observed
xtsum scrap grant grant_1 if scrap!=. // 54 firms observed over 3 years
Expand All @@ -85,13 +87,16 @@ xtsum scrap grant grant_1 if scrap!=. // 54 firms observed over 3 years
scrap: Variation between firms > variation over time within each firm
*/

* Identify highest/lowest scrap rates (extreme obs of the first variable listed)
bysort year: extremes scrap fcode // persistency: the same firms recur each year

* Table: Descriptive statistics - guide: repec.sowi.unibe.ch/stata/estout/esttab.html
estpost tabstat scrap lscrap grant /// scrap is right skewed (mean right of p50)
, statistics(mean sd min p50 max) columns(statistics) ///
listwise // omits obs with any of the chosen variables missing (sample comparable to 'regress')
esttab using "$tables/descriptive.tex", replace style(tex) delimiter("&") /// create/overwrite LaTeX file
label nonumbers nostar postfoot("\hline\end{tabular}") ///
cells("mean sd min p50 max") ///
cells("mean sd min p50 max") /// format is flexible for each cell
stats(N, fmt(%12.0gc) labels("Observations"))

* Table: Descriptive statistics by year
Expand All @@ -100,8 +105,8 @@ estpost tabstat scrap lscrap grant ///
listwise by(year) // show subsamples by year
esttab using "$tables/descriptive_yearly.tex", replace style(tex) delimiter("&") ///
label nonumbers nostar postfoot("\hline\end{tabular}") ///
cells("mean sd min p50 max count") ///
noobs // cells("count") makes it redundant to report observations in footer
cells("mean sd min p50 max count") /// count for each row; format is flexible
noobs // no observations reported in footer as cells("count") reports obs for each row insteads


********************************************************************************
Expand All @@ -112,29 +117,35 @@ esttab using "$tables/descriptive_yearly.tex", replace style(tex) delimiter("&")
gr two (kdensity scrap if d88==0 & d89==0 & grant_lead==1) ///
(kdensity scrap if d88==0 & d89==0 & grant_lead==0 & grant_lead2==0) ///
, legend(label(1 "Grant in 1988") label(2 "No grant")) ///
title("Panel A: Scrap rates in 1987") xtitle("Scrap rate (per 100 items)") ///
ytitle("Density") name(Fig_87, replace) // name for graph combine below
title("Panel A: Scrap rates in 1987") ///
xtitle("Scrap rate (per 100 items)") ytitle("Density") ///
xlab(0(5)30) ylab(0(.05).25) /// fix axis scales to match Fig_89
name(Fig_87, replace) // name for graph combine below
graph export "$figures/kernels_87.png", replace
sum scrap if d88==0 & d89==0 & grant_lead==1, detail // smallest=.28, p10=.45
sum scrap if d88==0 & d89==0 & grant_lead==0 & grant_lead2==0, detail // p10=.06
tab scrap if d88==0 & d89==0 & grant_lead==0 & grant_lead2==0
tab scrap if d88==0 & d89==0 & grant_lead==0 & grant_lead2==0 // five<.28; three>18
* Selection bias? No firm getting grant in 1988 scrapped less than 0.28% in 1987

* Figure: Kernel density in 1988 (by grant in 1988)
gr two (kdensity scrap if d88==1 & grant==1) ///
(kdensity scrap if d88==1 & grant==0 & grant_lead==0) ///
, legend(label(1 "Grant in 1988") label(2 "No grant")) ///
title("Panel B: Scrap rates in 1988") xtitle("Scrap rate (per 100 items)") ///
ytitle("Density") name(Fig_88, replace) // name for graph combine below
title("Panel A: Scrap rates in 1988") ///
xtitle("Scrap rate (per 100 items)") ytitle("Density") ///
xlab(0(5)30) ylab(0(.05).25) /// fix axis scales to match Fig_89
name(Fig_88, replace) // name for graph combine below
graph export "$figures/kernels_88.png", replace
* A scrap rate < 7% is now more common among the firms that receive grant in 1988

* Figure: Kernel density in 1989 (by grant in 1988)
gr two (kdensity scrap if d89==1 & grant_1==1) ///
(kdensity scrap if d89==1 & grant_1==0 & grant==0) ///
, legend(label(1 "Grant in 1988") label(2 "No grant")) ///
title("Panel C: Scrap rates in 1989") xtitle("Scrap rate (per 100 items)") ///
ytitle("Density") name(Fig_89, replace) // name for graph combine below
title("Panel C: Scrap rates in 1989") ///
xtitle("Scrap rate (per 100 items)") ytitle("Density") ///
xlab(0(5)30) /// add tick marks for every 5 items scrapped
name(Fig_89, replace) // name for graph combine below
graph export "$figures/kernels_89.png", replace
* Now a much larger share have a very low scrap rate regardless of grant history

Expand All @@ -149,15 +160,20 @@ graph export "$figures/kernels_combined.png", replace
********************************************************************************
estimates clear // clear estimates before creating table of estimation results

* Standard pooled OLS as a baseline
* Baseline (standard pooled OLS with year dummies)
reg lscrap grant grant_1 d88 d89 // grant is insignificant
est store baseline, title("Baseline")

* Standard pooled OLS simplified with a yearly time trend instead of year dummies
* Baseline simplified with a yearly time trend instead of year dummies
reg lscrap grant grant_1 trend // grant is insignificant
est store trend, title("Trend")

* Standard pooled OLS with dummies to capture firm-specific effects
* Take a look at the standard errors (detect outliers)
predict uhat, residuals // save predicted error term of the last regression
extremes uhat fcode year scrap, n(10) // unobserved firm-specific effects (permanent differences)
drop uhat // remove the uhat variable such that it can be predicted again

* Baseline extended with dummies to capture firm-specific effects
reg lscrap grant grant_1 d88 d89 i.fcode // identical to FE estimation but for constant and dummies
est store dummies, title("Dummies")

Expand All @@ -173,13 +189,13 @@ est store FE_cluster, title("FE cluster robust") // see appendix 14A.2 in Wooldr
estout * using "$tables/results.xls", replace /// create/overwrite Excel workbook
starlevels(* .10 ** .05 *** .01) mlabels(,titles numbers) label /// use model titles & variable labels
cells( b(star fmt(4)) se(par fmt(4)) ) ///
stats( r2 N N_g g_avg, fmt(4 %12.0gc) labels("R-squared" "Obs." "Number of firms" "Obs. per firm") )
stats( r2 N N_g g_avg, fmt(%12.4gc) labels("R-squared" "Obs." "Number of firms" "Obs. per firm") )

* Save reduced estimation results as LaTeX file (without dummies)
estout * using "$tables/results.tex", replace style(tex) /// create/overwrite LaTeX file
starlevels(* .10 ** .05 *** .01) mlabels(,titles numbers) label ///
cells( b(star fmt(4)) se(par fmt(4)) ) ///
stats( r2 N N_g g_avg, fmt(4 %12.0gc) labels("R$^2$" "Obs." "Number of firms" "Obs. per firm") ) ///
stats( r2 N N_g g_avg, fmt(%12.4gc) labels("R$^2$" "Obs." "Number of firms" "Obs. per firm") ) ///
drop(_cons) indicate("Firm dummies=*fcode*") /// omit constant and firm dummies
prehead("\begin{tabular}{lccccc}\hline") /// MANUALLY FIT NUMBER OF C's TO NUMBER OF MODELS!
posthead("\hline") prefoot("\hline") ///
Expand Down
60 changes: 38 additions & 22 deletions Example_Stata_Word.do
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
* MIT LICENSE: Copyright (c) 2023 Thor Donsby Noe (give credit; no liability)
********************************************************************************
/* Installations
ssc install bcuse // access Wooldridge datasets for the examples below
ssc install estout // export tables to Excel, Word, or LaTeX (descriptive)
ssc install outreg2 // export tables to Excel, Word (estimation results)
ssc install bcuse // access Wooldridge datasets for the examples below
ssc install estout // export tables to Excel, Word, or LaTeX (descriptive)
ssc install outreg2 // export tables to Excel, Word (estimation results)
ssc install extremes // list extreme observations for a variable
*/

* Change directory to the folder with your data files (redundant for bcuse)
Expand Down Expand Up @@ -60,15 +61,16 @@ label variable trend "Time trend" // covering year t in {0,1,2}
********************************************************************************
* DESCRIPTIVE ANALYSIS (of panel data)
********************************************************************************
* Take a first look at the data
* Take a first look at the data (by year)
xtdescribe // balanced panel of 157 firms observed each year 1987-89
sort year fcode // sort data by year and firm (required for "by year" command)
by year: tab grant if scrap!=. // scrap only recorded for 54 of the 157 firms
by year: sum scrap grant grant_1 if scrap!=. // scrap rate is reduced each year
correlate scrap year // scrap rate has a negative correlation with time
correlate scrap grant_lead grant_lead2 if d88==0 & d89==0 // is treatment assignment random?
bysort year: tab grant if scrap!=. // scrap only recorded for 54 of the 157 firms
/* Of the 54 firms for which scrap rate is recorded,
19 firms (35.2 %) received a grant in 1988,
and another 10 firms (18.5 %) received a grant in 1989.
*/
bysort year: sum scrap grant grant_1 if scrap!=. // mean scrap rate decreases each year

* Take a closer look at variation in the reduced sample where scrap is observed
xtsum scrap grant grant_1 if scrap!=. // 54 firms observed over 3 years
Expand All @@ -85,23 +87,26 @@ xtsum scrap grant grant_1 if scrap!=. // 54 firms observed over 3 years
scrap: Variation between firms > variation over time within each firm
*/

* Identify highest/lowest scrap rates (extreme obs of the first variable listed)
bysort year: extremes scrap fcode // persistency: the same firms recur each year

* Table: Descriptive statistics - guide: repec.sowi.unibe.ch/stata/estout/esttab.html
estpost tabstat scrap lscrap grant /// scrap is right skewed (mean right of p50)
, statistics(mean sd min p50 max) columns(statistics) ///
listwise // omits obs with any of the chosen variables missing (sample comparable to 'regress')
esttab using "$tables/descriptive.rtf", replace /// create/overwrite Word document
label nonumbers modelwidth(9) ///
cells("mean sd min p50 max") ///
cells("mean sd min p50 max") /// format is flexible for each cell
stats(N, fmt(%12.0gc) labels("Observations"))

* Table: Descriptive statistics by year
estpost tabstat scrap lscrap grant ///
, statistics(mean sd min p50 max count) columns(statistics) /// count obs for each row
listwise by(year) // show subsamples by year
esttab using "$tables/descriptive_yearly.rtf", replace ///
label nonumbers modelwidth(8) /// narrow modelwidth requires fewer digits (set manually)
label nonumbers modelwidth(8) /// narrow modelwidth only leaves space for 2 digits (set format manually)
cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2)) p50(fmt(2)) max(fmt(2)) count(fmt(0))") ///
noobs // cells("count") makes it redundant to report observations in footer
noobs // no observations reported in footer as cells("count") reports obs for each row instead


********************************************************************************
Expand All @@ -112,29 +117,35 @@ esttab using "$tables/descriptive_yearly.rtf", replace ///
gr two (kdensity scrap if d88==0 & d89==0 & grant_lead==1) ///
(kdensity scrap if d88==0 & d89==0 & grant_lead==0 & grant_lead2==0) ///
, legend(label(1 "Grant in 1988") label(2 "No grant")) ///
title("Panel A: Scrap rates in 1987") xtitle("Scrap rate (per 100 items)") ///
ytitle("Density") name(Fig_87, replace) // name for graph combine below
title("Panel A: Scrap rates in 1987") ///
xtitle("Scrap rate (per 100 items)") ytitle("Density") ///
xlab(0(5)30) ylab(0(.05).25) /// fix axis scales to match Fig_89
name(Fig_87, replace) // name for graph combine below
graph export "$figures/kernels_87.png", replace
sum scrap if d88==0 & d89==0 & grant_lead==1, detail // smallest=.28, p10=.45
sum scrap if d88==0 & d89==0 & grant_lead==0 & grant_lead2==0, detail // p10=.06
tab scrap if d88==0 & d89==0 & grant_lead==0 & grant_lead2==0
tab scrap if d88==0 & d89==0 & grant_lead==0 & grant_lead2==0 // five<.28; three>18
* Selection bias? No firm getting grant in 1988 scrapped less than 0.28% in 1987

* Figure: Kernel density in 1988 (by grant in 1988)
gr two (kdensity scrap if d88==1 & grant==1) ///
(kdensity scrap if d88==1 & grant==0 & grant_lead==0) ///
, legend(label(1 "Grant in 1988") label(2 "No grant")) ///
title("Panel B: Scrap rates in 1988") xtitle("Scrap rate (per 100 items)") ///
ytitle("Density") name(Fig_88, replace) // name for graph combine below
title("Panel A: Scrap rates in 1988") ///
xtitle("Scrap rate (per 100 items)") ytitle("Density") ///
xlab(0(5)30) ylab(0(.05).25) /// fix axis scales to match Fig_89
name(Fig_88, replace) // name for graph combine below
graph export "$figures/kernels_88.png", replace
* A scrap rate < 7% is now more common among the firms that receive grant in 1988

* Figure: Kernel density in 1989 (by grant in 1988)
gr two (kdensity scrap if d89==1 & grant_1==1) ///
(kdensity scrap if d89==1 & grant_1==0 & grant==0) ///
, legend(label(1 "Grant in 1988") label(2 "No grant")) ///
title("Panel C: Scrap rates in 1989") xtitle("Scrap rate (per 100 items)") ///
ytitle("Density") name(Fig_89, replace) // name for graph combine below
title("Panel C: Scrap rates in 1989") ///
xtitle("Scrap rate (per 100 items)") ytitle("Density") ///
xlab(0(5)30) /// add tick marks for every 5 items scrapped
name(Fig_89, replace) // name for graph combine below
graph export "$figures/kernels_89.png", replace
* Now a much larger share have a very low scrap rate regardless of grant history

Expand All @@ -148,20 +159,25 @@ graph export "$figures/kernels_combined.png", replace
* ESTIMATION (panel analysis elaborates on Table 14.1 in Wooldridge 7e, p. 464)
* Replace ".doc" with ".xls" to produce an Excel workbook with results instead
********************************************************************************
* Standard pooled OLS as a baseline
* Baseline (standard pooled OLS with year dummies)
reg lscrap grant grant_1 d88 d89 // grant is insignificant
outreg2 using "$tables/results.doc", replace /// create/overwrite Word document
ctitle("Baseline, (se)") label nocons // use variable labels and omit constant

* Standard pooled OLS simplified with a yearly time trend instead of year dummies
* Baseline simplified with a yearly time trend instead of year dummies
reg lscrap grant grant_1 trend // grant is insignificant
outreg2 using "$tables/results.doc", /// append to existing Word table
ctitle("Trend, (se)") label nocons

* Standard pooled OLS with dummies to capture firm-specific effects

* Take a look at the standard errors (detect outliers)
predict uhat, residuals // save predicted error term of the last regression
extremes uhat fcode year scrap, n(10) // unobserved firm-specific effects (permanent differences)
drop uhat // remove the uhat variable such that it can be predicted again

* Baseline extended with dummies to capture firm-specific effects
reg lscrap grant grant_1 d88 d89 i.fcode // identical to FE estimation but for constant and dummies
outreg2 using "$tables/results.doc", ///
drop(i.fcode) addtext(Firm dummies, Yes) /// omit firm dummies
drop(i.fcode) addtext(Firm dummies, Yes) /// omit firm dummies but note it
ctitle("Dummies, (se)") label nocons

* FE estimation: time-demeaning eliminates firm-specific effect (within-transformation)
Expand Down
Binary file modified Figures/kernels_87.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Figures/kernels_88.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Figures/kernels_89.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Figures/kernels_combined.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion LaTeX/bibliography.bib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% copy citation from https://Scholar.Google.com
% or generate using e.g. https://truben.no/latex/bibtex
% or generate from e.g. https://truben.no/latex/bibtex
@article{holzer1993training,
title={Are training subsidies for firms effective? The Michigan experience},
Expand Down
Binary file removed LaTeX/figures/kernels_87.png
Binary file not shown.
Binary file removed LaTeX/figures/kernels_88.png
Binary file not shown.
Binary file removed LaTeX/figures/kernels_89.png
Binary file not shown.
Binary file modified LaTeX/figures/kernels_combined.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LaTeX/main.pdf
Binary file not shown.
18 changes: 9 additions & 9 deletions LaTeX/main.tex
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
\documentclass[11pt]{article}
\input{preample/packages}
\input{preample/citations}
\input{preample/hyperlinks}
\input{preample/notes}
\input{preample/ref_commands}
\input{preample/title_page} % edit title & author(s) in title_page.tex
\input{preamble/packages}
\input{preamble/citations}
\input{preamble/hyperlinks}
\input{preamble/notes}
\input{preamble/ref_commands}
\input{preamble/title_page} % edit title & author(s) in title_page.tex
\addbibresource{bibliography.bib} % add references to bibliography.bib

%---------------------------------------------------------------
%-------- TITLE PAGE AND TABLE OF CONTENTS ---------------------
%---------------------------------------------------------------
\begin{document}
\begin{titlingpage}
\maketitle
\maketitle % using preamble/title_page.tex
\centering
\includegraphics[width=.5 \textwidth]{figures/Logo}
% \begin{abstract}
% \end{abstract}
\vfill % add vertical fill (push contents down to bottom of page)
\vfill % adds vertical fill (push contents down to bottom of page)
\tableofcontents
\end{titlingpage}

Expand All @@ -43,7 +43,7 @@
%---------------------------------------------------------------
\clearpage
\appendix
\setcounter{page}{1}\pagenumbering{roman} % page numbering i, ii, iii, iv...
\setcounter{page}{1}\pagenumbering{roman} % page numbering i, ii...
% \renewcommand{\theequation}{\thesection.\arabic{equation}} % add appendix letter to equation numbering

\input{sections/appendix}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions LaTeX/sections/conclusion.tex
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
% BRIEFLY EXPLAIN WHAT HAS BEEN DONE?
% BRIEFLY DISCUSS MAIN RESULTS AND CONCLUSIONS
% BRIEFLY DISCUSS LIMITATIONS AND POSSIBLE EXTENSIONS
\section{Conclusion}
\label{s:conclusion}
The verdict on whether the estimated effects are significant is very sensitive to model choice. Identification of the effects of the training grant is further challenged by a low number of observations, large heterogeneity in scrap rates, and concerns about selection bias.
3 changes: 3 additions & 0 deletions LaTeX/sections/data.tex
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
% CHARACTERISTICS OF DATASET (SOURCE, TYPE OF DATA)
% DESCRIPTION OF MAIN VARIABLES
% DESCRIPTIVE STATISTICS OF MAIN VARIABLES
\section{Data}
\label{s:data}

Expand Down
4 changes: 4 additions & 0 deletions LaTeX/sections/discussion.tex
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
% ARE RESULTS ROBUST TO DIFFERENT SPECIFICATIONS? (DIFFERENT VARIABLES OR DATA SELECTION)
% RESULTS' IMPLICATIONS FOR PUBLIC POLICY? (ECONOMIC SIGNIFICANCE)
% ARE RESULTS COMPARABLE TO THE LITERATURE? (DATA, METHOD, PARAMETER ESTIMATES)
% POSSIBLE WEAKNESSES AND EXTENSIONS? (BEYOND THE SCOPE OF THIS PAPER)
\section{Discussion}
\label{s:discussion}

Expand Down
2 changes: 1 addition & 1 deletion LaTeX/sections/intro.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ \section{Introduction}
% MAIN RESULTS


% OVERVIEW OF THIS PAPER
% STRUCTURE OF THIS PAPER
I proceed with presenting the data in \sref{s:data}, empirical model in \sref{s:model}, and results in \sref{s:results} before discussion in \sref{s:discussion} and conclusion in \sref{s:conclusion}.
Loading

0 comments on commit 23cccd5

Please sign in to comment.