I am very grateful for statlist solving all my problems (I never had to ask a single question) over the last 4 and a bit years of a nearly completed PhD.
From zero knowledge of econometrics, programming or STATA I have been able to work towards a degree of expertise sufficient for my own PhD.
As a means of giving back I will share my solution, which experienced programmers and STATAlisters will probably find very clunky. However, there seems to be very little out there on directly solving this.
Basically, I want my regression output from ivreg2 to print to dir: sseout. This is no problem, e.g.
the Addstat option is useful, e.g.
The problem arises when wanting to take stats from a matrix stored in the results because addstat doesn't support that directly, to my knowledge, only scalars effectively.
The only other references I've found to support this are:
link: http://www.princeton.edu/~otorres/Stata/publish.htm
link: http://www.princeton.edu/~otorres/Stata/publish.htm
Both of which, I was not able to use to solve the problem I had. For my example, I want to have Shea's Partial R-Squared printed from the first stage regressions for each instrumented endogenous variable. This is stored in the matrix: e(first). Here is my solution worked out today. I have called it MatScalOut and it is reliant on outreg2 and ivreg2 in addition to estout. I take no credit for these excellent programs/ado files and corresponding help files.
Anyone can run this code to test it, with the following to bear in mind (disclaimer!)
1. Ensure you have a c:/temp directory, if not create that folder
2. Uncomment the ssc install lines for any or all of the three programs you do not have
3. Run through doedit (copy, paste and [CTRL]+d should do the trick.
I hope that this does not break convention too much by posting this. I want to give back for all the help from past Q&As of others. Hopefully, this will solve a lot of problems for people creating regression output tables using ivreg and assist in automation when scalar values are needed to represent matrix entries in order to output using outreg2 and the addstat option.
Comments, criticisms, streamlines, conventions I have broken and need to correct for the purposes of STATAList etc more than welcome.
Best wishes,
Sam Beatson
From zero knowledge of econometrics, programming or STATA I have been able to work towards a degree of expertise sufficient for my own PhD.
As a means of giving back I will share my solution, which experienced programmers and STATAlisters will probably find very clunky. However, there seems to be very little out there on directly solving this.
Basically, I want my regression output from ivreg2 to print to dir: sseout. This is no problem, e.g.
Code:
sysuse auto.dta, clear //ssc install outreg2 //ssc install ivreg2 ivreg2 price weight length (turn=gear) outreg using c:/temp/ivreg2.log, replace
Code:
outreg using c:/temp/ivreg2.log, adds(Anystat, e(archi2)) append
The only other references I've found to support this are:
link: http://www.princeton.edu/~otorres/Stata/publish.htm
link: http://www.princeton.edu/~otorres/Stata/publish.htm
Both of which, I was not able to use to solve the problem I had. For my example, I want to have Shea's Partial R-Squared printed from the first stage regressions for each instrumented endogenous variable. This is stored in the matrix: e(first). Here is my solution worked out today. I have called it MatScalOut and it is reliant on outreg2 and ivreg2 in addition to estout. I take no credit for these excellent programs/ado files and corresponding help files.
Anyone can run this code to test it, with the following to bear in mind (disclaimer!)
1. Ensure you have a c:/temp directory, if not create that folder
2. Uncomment the ssc install lines for any or all of the three programs you do not have
3. Run through doedit (copy, paste and [CTRL]+d should do the trick.
Code:
/* ****MATSCALOUT**** Program to retrieve Shea's Partial R Squared (or any matrix entry) after ivreg2 and print it using outreg2 addstat option By Sam Beatson, PhD Candidate, University of Nottingham Research Centre for Finance and Banking of the School of Contemporary Chinese Studies Email: [email protected] [as written] */ //Usage: Can be used to capture any of the statistics stored in the matrices of such programs and print them through the addstat option of outreg //Log capture log close log using c:/temp/Sheas.log, replace //Open dataset sysuse auto.dta, clear //Requires: estout, outreg2 and ivreg2. Uncomment below if not installed on first run /* ssc install estout, update ssc install outreg2, update ssc install ivreg2, update */ //Perform instrumental variables regression ivreg2 price weight length (turn=gear), savefirst //Create a usable matrix from the matrix containing Shea's Partial R-Squared matrix list e(first) matrix shea=e(first) svmat shea, name(shea) gen UN=_n //NB. For next line, need to make sure Shea's partial R-Squared is now in row 1 of the 'shea(i)' variable su shea1 if UN==1 scalar de SheaOne=r(mean) estadd scalar SheaOne //If more than one IV /* su shea2 if UN==1 scalar de SheaTwo=r(mean) estadd scalar SheaTwo */ outreg2 using c:/temp/ivregauto.log, adds(Shea's Partial R^2 Var 1, SheaOne/*, SPR^2 Var 2, SheaTwo*/) cttop("IV Regression") replace
Comments, criticisms, streamlines, conventions I have broken and need to correct for the purposes of STATAList etc more than welcome.
Best wishes,
Sam Beatson
Comment