Economic stata

profileGHOST HAM
65376_1788309_Econ120_Summer2020_Stata_final.pdf

UC San Diego Econometrics 120C

Department of Economics Summer I 2020

Stata Assignment

Due: 11:59pm July 25, 2020

Instructions

The data file to be used for this assignment is chem patents maindataset.dta. The do file is PS.do.

First, create a working directory (a folder) in your system. Save these two files (the data file and the

do file) in that folder. Rename the do file with “PS yourPID”. That is, if your PID is A34567890,

then your file should be named “PS A34567890.do”.

You will do this assignment by modifying the lines in this do file itself. This do file will guide you

through the exercises. It has commented blanks for you to fill. For the questions which require an

answer in words, write the answer as a comment in the same do file. In Stata, all lines starting with

an asterisk (*) and all lines enclosed by ”/*” and ”*/” are considered as comments. You must update

these blanks within the same do file and upload the do file. Only the final do file needs to be

uploaded. Make sure your code runs; if it does not run you will be subtracted 25% from

your final score.

Please solve all the questions using Stata 16 which is available for download on Canvas.

1 Monte Carlo experiment

Consider the following data generating process

Yi = β0 + β1 ·Xi + ui (1)

Xi = ei + γ ·ui (2)

where ei iid∼ N(0, 1) and ui

iid∼ N(0, 1) are independent, i = 1, . . . ,N. Recall that the OLS estimator of β1 is β̂1 =

Ĉov(Xi,Yi)

V̂ ar(Xi) . By using LLN and CMT we can derive.

β̂1 p →

Cov(Xi,Yi)

V ar(Xi) = β1 +

Cov(Xi,ui)

V ar(Xi) = β1 +

Cov(ei + γ ·ui,ui) V ar(ei + γ ·ui)

= β1 + γ

1 + γ2

Let β0 = 1 and β1 = 3. In this exercise you need to simulate the distributions of β̂1 using Monte

Carlo method. In order to do this, generate samples of size N from model (1)-(2), compute the OLS

estimate β̂1 from generated data, and repeat this process 10,000 times.

1. Set N = 1, 000. Simulate the distribution of β̂1 using 10,000 Monte Carlo repetitions as described

above for two cases: (1) γ = 0; (2) γ = 2. Plot the sampling distribution of β̂1 for each case,

find the mean E[β̂1] and compare its value with β1 = 3. Comment on your findings and the

shapes of the distributions. Are those results expected?

1

The first part of the file PS.do shows you how to perform such an experiment. You can use the

code there in your solution but keep in mind that it has six gaps that you will have to fill before

it can run successfully.

2. Set N = 10 and consider the first case only: γ = 0. Plot the sampling distribution of β̂1 and

compare it to the one with γ = 0 and N = 1, 000. What property of β̂1 does it illustrate?

2 Patent data

2.1 Background

The application in this section comes from Moser and Voena (AER, 2012)1. The paper studies

the long-run effects of compulsory licensing on domestic invention. Some background information

provided by the authors:

Compulsory licensing allows firms in (a) developing country to produce foreign inventions without

the consent of foreign patent owners. ... To identify the long-run effects of compulsory licensing

on domestic invention, this paper takes advantage of an exogenous episode of compulsory licensing

as a result of World War I. In November 1917, Congress passed the Trading with the Enemy

Act (TWEA). Section 10 of the Act permitted U.S. firms to violate enemy-owned patents if they

contributed to the war effort.

To measure the effects of compulsory licensing, this paper compares changes in annual patents for

chemical inventions by domestic inventors across technologies that were differentially affected by

the TWEA.

2.2 Data

The file chem patents maindataset.dta contains part of the data that the authors use for their study.

We will borrow it for our exercises. The data is a panel covering a variety of technologies from 1875

to 1939. Here is a brief description of some key variables in the dataset.

1. grntyr: year.

2. class id: identifier for a technology, measured by a narrowly-defined subclass of US Patent

Office patents.

3. Treat: a dummy variable. It is equal to 1 if at least one domestic firm in the technology subclass

was issued a compulsory license under the TWEA; it is equal to 0 otherwise.

4. CountUSA: the number of US patents for chemical inventions granted to US domestic inventors

per subclass and year.

5. CountCl: the number of enemy-owned patents that were actually licensed under the TWEA per

subclass and year.

6. CountClITT : the number of enemy-owned patents that US firms could have licensed under the

TWEA per subclass and year.

1Moser, Petra, and Alessandra Voena. 2012. “Compulsory Licensing: Evidence from the Trading with the Enemy

Act.” American Economic Review, 102 (1): 396-427.

2

2.3 Exercises

1. Use the tab command to learn about categorical variables.

(a) What sample period does the data span?

(b) In which year did the firms start to receive compulsory licensing? (Hint: Use the tab

command to create a cross-frequency table of grntyr and treat, and find the first year when

treat took a value of one.)

2. Use the sum command to learn more about the summary statistics of the data. What were the

maximum, minimum and mean of count usa, the number of US patents that were invented in a

class in a year?

3. Use the histogram command to plot the distribution of count cl in 1919.

(a) Describe the shape of the distribution.

(b) Roughly speaking, how many subclasses had a non-zero count cl? (Hint: add , freq to the

end of the histogram command.)

4. Create a dummy variable from grntyr for every year in the data. Take the first year 1875 as

an example. Generate a new variable and name it td1. Set its value to 1 if the observation is

for Year 1875 and 0 otherwise. Do the same for all the years in the data. Because there are 65

years in total you will end up with 65 dummy variables, td1 ... td65. For this exercise, simply

learn from the code in the PS.do file to see how it is done in one line.

5. Use the reg command to run OLS regressions (3) and (3) to study the effect of compulsory

licensing to US domestic innovations.

CountUSAs,t = α0 + α1Treats,t + us,t (3)

CountUSAs,t = β0 + β1CountCls,t + us,t (4)

where s is an index for a subclass and t is an index for a year.

6. Repeat the regressions with the time dummies you created in Part 4.

CountUSAs,t = α0 + α1Treats,t + 64∑ n=1

α̃ntdnt + us,t (5)

CountUSAs,t = β0 + β1CountCls,t +

64∑ n=1

β̃ntdnt + us,t (6)

where s is an index for a subclass; t is an index for a year; tdn (n = 1, . . . , 64) is a dummy

variable for Year n. In Stata, you could use td1 -td64 to incorporate multiple dummies, td1, . . . ,

td64, in your regression.

(a) The PS.do file provides an example to run (5). Complete the command for running (6).

(b) Why don’t we include all the dummies, td1 -td65, in the regressions above when the constant

term is present?

3

7. Let’s focus on Equation (6). One concern with the OLS regressions above is that CountCl may

have been an endogenous decision, i.e. the firms in a subclass of technology that received more

licensing may have chosen to do so because they lacked innovations themselves. This means

that they would have fewer patents (a smaller u) to begin with. If this were true, we would

have cov(CountCl,u) < 0. An OLS estimate would then be biased downward.

(a) The paper decides to solve the endogeneity problem by instrumenting CountCl with Count-

ClITT. What are the two key assumptions that CountClITT needs to satisfy in order for

the IV strategy to work?

(b) Use the ivregress 2sls command to implement the IV strategy for (6). This command will let

Stata do all the work for you. Remember to include the time dummies as before. Compare

the IV estimate with the OLS estimate above. Is the endogeneity concern justified?

(c) Use reg to manually estimate the two stages. Remember to include the time dummies in

both stages.

Stage 1: CountCls,t = φ0 + φ1CountClITTs,t +

64∑ n=1

φ̃ntdnt + us,t (7)

Stage 2: CountUSAs,t = γ0 + γ1 ̂CountCls,t + 64∑ n=1

γ̃ntdnt + es,t (8)

where ̂CountCls,t is the fitted value from (7). Compare the estimate, γ̂1, with what you got in (b). Is it what you expected?

4