Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Re: st: Re: st: Re: st: From: Rodrigo Briceño <rjbriceno@gmail.com> |

Date |
Tue, 25 Sep 2012 18:36:05 +0100 |

Thanks for the thanks. As said, I don't use -estadd- or -estout-. That means no more than it says. (I don't often collate lots of model results, and when I do I tend to write my own code.) I was not commenting adversely on those programs, just making the standard point that has been part of Statalist protocol over most of its history that you are asked to explain where user-written commands come from. The logic is three-fold at least: 1. People trying to make sense of your problem get information they need. (If they know already, no harm is done.) You don't want to make anything more difficult for those people. 2. Even people just watching may learn about a useful program if they ever have a problem similar to yours. That's surely a useful side-effect 3. The program authors get (indirect) publicity for their work. Any way, it follows that I can't recommend alternatives, but I have every reason to believe that you don't need alternatives, as I know that Ben Jann is an excellent programmer and people whose judgement I trust use those programs often. Nick On Tue, Sep 25, 2012 at 6:24 PM, Rodrigo Briceño <rjbriceno@gmail.com> wrote: > Dear Nick. I really appreciate your comments. I will test the > recommended changes. > I decided to use estadd and estout in order to produce the table with > the summarized results from my regressions. > Is there any other more efficient way to execute that procedure? > > Thanks again for helping a researcher from the other side of the sea. > > 2012/9/25 Nick Cox <njcoxstata@gmail.com>: >> In principle the way to start that off is an outer loop >> >> foreach j in 8 225 29 220 18 251 222 221 244 24 276 { >> >> ... if isin == `j' >> >> } >> >> but you may need to make other changes. >> >> I have various other comments on your code. >> >> 0. You use -estout- and -estadd-, which are user-written programs, so >> you are asked to explain where they come from. >> >> 1. There is unnecessary creation of locals to act as what I call "middle macros" >> >> local hettest = r(nr2) >> local hetprob = r(nr2p) >> estadd scalar hettest = `hettest' >> estadd scalar hetp = `hetprob' >> >> can be condensed to >> >> estadd scalar hettest = r(nr2) >> estadd scalar hetp = r(nr2p) >> >> 2. The use of matrices to hold constants is also not needed, sp >> >> matrix bgchi2s = r(chi2) >> matrix bgchi2p = r(p) >> estadd scalar bgchi2s = bgchi2s[1,1] >> estadd scalar bgchi2p = bgchi2p[1,1] >> >> reduces to two lines similarly. >> >> 3. The Jarque-Bera test consists of using asymptotic results for >> skewness and kurtosis of Gaussians for small samples. It's a widely >> kept secret that it has terrible properties. A few simulations is >> enough to convince that convergence is appallingly slow. >> >> 4. That said, >> >> tabstat ehat, stats(skewness kurtosis) column(variable) save, if isin==8 >> matrix stats=r(StatTotal) >> local SK=stats[1,1] >> local KU=stats[2,1] >> gen jb = (e(N)/6)*((`SK')^2+(`KU'-3)^2/4) if isin==8 >> egen jb1=max(jb) >> estadd scalar jb=jb1 >> >> is also roundabout. The variable -jb- just is holding a constant, so >> the -egen- call is redundant. >> >> su ehat if isin == 8, detail >> estadd scalar jb = (r(N)/6)*((r(skewness)^2+(r(kurtosis) - 3)^2/4) >> >> is, I believe, equivalent. >> >> 5. The two -forvalues- loops could be collapsed to one. In fact, it is >> not necessary to -generate- lagged variables because -regress- will >> create them on the fly. >> >> Although I haven't tested it I thus suggest that your code (apart from >> the -estout- call) simplifies to >> >> local X "sfid liqmk dv pprom" >> >> forvalues i=1(1)24 { >> regress liq `X' l`i'.liq if isin==8 >> predict ehat if e(sample), res >> >> ivhettest, ivsq >> estadd scalar hettest = r(nr2) >> estadd scalar hetp = r(nr2p) >> >> estat bgodfrey, lags(1) >> estadd scalar bgchi2s = r(chi2) >> estadd scalar bgchi2p = r(p) >> >> su ehat, detail >> estadd scalar jb = (r(N)/6)*((r(skewness)^2+(r(kurtosis) - 3)^2/4) >> scalar work = (r(N)/6)*((r(skewness)^2+(r(kurtosis) - 3)^2/4) >> estadd scalar jbp = chiprob(2,work) >> >> drop ehat >> estimates store m`i', title(m`i') >> } >> >> The line -scalar work ...- may be redundant but I don't ever use >> -estout- or -estadd-, so I can't be sure. >> >> Simplifying the code in this way may help you generalise it by adding >> an outer loop. I suspect that the line >> >> estimates store m`i', title(m`i') >> >> would need to become something more like >> >> estimates store m`i'_`j', title(m`i'_`j') >> >> Nick >> >> On Tue, Sep 25, 2012 at 5:03 PM, <owner-statalist@hsphsun2.harvard.edu> wrote: >>> Hello Statalisters. I have a do file that use a macro in order to run >>> several regression models, using different lags each time. What I'm >>> following pasting is the syntax corresponding to ISIN=8. I have eleven >>> different ISIN (let's call them IDs). How can I introduce the issue of >>> different values there. I think this a matter of nesting, but I never >>> have used that. Even the text file with the results is associated to >>> the number (ISIN) selected. My full list includes 8, 225, 29, 220, 18, >>> 251, 222 ,221, 244, 24, 276 >>> >>> Thanks for your contribution >>> >>> ------------------------------------------------------------------------- >>> >>> forvalues i=1(1)24 { >>> gen l`i'liq=l`i'.liq >>> } >>> >>> local X = "sfid liqmk dv pprom" >>> >>> forvalues i=1(1)24 { >>> regress liq `X' l`i'liq if isin==8 >>> predict ehat if e(sample), res >>> ivhettest, ivsq >>> local hettest = r(nr2) >>> local hetprob = r(nr2p) >>> estadd scalar hettest = `hettest' >>> estadd scalar hetp = `hetprob' >>> estat bgodfrey, lags(1) >>> matrix bgchi2s = r(chi2) >>> matrix bgchi2p = r(p) >>> estadd scalar bgchi2s = bgchi2s[1,1] >>> estadd scalar bgchi2p = bgchi2p[1,1] >>> *jarque bera >>> tabstat ehat, stats(skewness kurtosis) column(variable) save, if isin==8 >>> matrix stats=r(StatTotal) >>> local SK=stats[1,1] >>> local KU=stats[2,1] >>> gen jb = (e(N)/6)*((`SK')^2+(`KU'-3)^2/4) if isin==8 >>> egen jb1=max(jb) >>> estadd scalar jb=jb1 >>> estadd scalar jbp=chiprob(2,jb1) >>> drop ehat jb jb1 >>> *end of jarque bera >>> estimates store m`i', title(m`i') >>> } >>> >>> estout * using modisin8.txt, cells(b(star fmt(%9.3f)) p(fmt(%9.3f))) >>> starlevels(* .10 ** .05 *** .01) stats(r2 N hettest hetp bgchi2s >>> bgchi2p jb jbp, fmt(%9.3f %9.0g %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f) >>> labels(R-squared)) legend label collabels(none) varlabels(_cons >>> Constant) >>> drop _est* >>> drop l*liq >>> save, replace * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: From: Rodrigo Briceño <rjbriceno@gmail.com>***From:*owner-statalist@hsphsun2.harvard.edu

**st: Re: st: From: Rodrigo Briceño <rjbriceno@gmail.com>***From:*Nick Cox <njcoxstata@gmail.com>

**st: Re: st: Re: st: From: Rodrigo Briceño <rjbriceno@gmail.com>***From:*Rodrigo Briceño <rjbriceno@gmail.com>

- Prev by Date:
**RE: st: SUREG with if command.** - Next by Date:
**Re: st: SUREG with if command.** - Previous by thread:
**st: Re: st: Re: st: From: Rodrigo Briceño <rjbriceno@gmail.com>** - Next by thread:
**st: chisquare for trend** - Index(es):