Sunday, April 10, 2011

Video Tutorial on IV Regression

Update: [1 May 2011] I am working on a better augmentation of the current IV regression functions (specifically ivreg() in AER) in R. I will post a link here to my new method/function for IV regression when I finish debugging the code.

Update 2: [15 May 2011] The function I wrote here does not work with factors due to the way in which I constructed fitted values for the standard error correction in the second stage.

I recorded a new video tutorial on how to conduct an IV regression. This time I used my new ivregress() command, which has much better syntax than my old one. There are several reasons I needed to do this:

  1. Relative to my previous post on IV regression, I have added the ability to conduct overidentifying tests. Now, my ivregress() command has all of the basic functionality of Stata's 2sls option to ivregress.
  2. Relative to my previous video tutorial on IV regression, this video uses my newer command, which as much better syntax. As such, I will use this video tutorial to replace the old one.

Here is the R script file I used to define my ivregress() command and its companion summary command sum.iv().



To get ivregress() and sum.iv() to work, (1) copy the text in the above text box into an R script, (2) run all (or just download and run the R script) and (3) save into your default workspace if you want to use the commands into the future. Then, you're good to go. See my video demonstrating how to use the command here:



Here is the code I used to produce the output in the video.



Finally, here is a link to the synthetic "market share" data I used in the video.

I hope you find this command helpful.

3 comments:

  1. Hey Tony,

    Can you tell me if this package is geared for your specific data set or have you tried multiple data sets?

    Douglas from Michigan

    ReplyDelete
  2. Douglas,

    I have tested it on my own data set (to make sure it matches Stata's calculations exactly), but I wrote the function to work for any data set where you have one endogenous variable (and possibly many instruments). If you have more than one endogenous variable, my function won't do that (yet... I may add that functionality in my next update).

    ReplyDelete
  3. Tony,

    Great video and code. Thanks!

    Would it be possible to share the code used to generate the dataset mktshare.dta ?

    Also the link to the data (mktshare.dta) seems to have too many redirects. Can you make it available as a CSV file (mktshare.dta.SCV.txt)?

    Thanks,
    James

    ReplyDelete