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 |
Rebecca Pope <rebecca.a.pope@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: strange kdensity behavior |

Date |
Fri, 31 May 2013 15:29:43 -0500 |

Thanks Austin and Nick. I missed the nuance that the -addplot- option used -twoway kdensity-. Setting the number of estimation points does indeed ensure equivalent results. That said, no amount of adjusting the estimation points seems to improve the fit of the curve for std. dev. > 1. I think I'll just stick to generating the density for my reference distributions from their pdf's. For posterity, Nick's suggestion to -generate- the density and re-graph produces "prettier" graphs if the -at(varname)- option is specified for -kdensity-. This means, however, that the -n()- option can't be used. Building on the code I already posted, this just illustrates the "zoom" that I mentioned earlier and shows the difference between the pdf and the kernel density estimate. **** /* True Lognormal pdf evaluated at drawn value of X */ gen pdfx = 1/(lognorm*sqrt(2*_pi*`sig'^2))*exp(-((ln(lognorm)-`mu')^2)/(2*`sig'^2)) /* Obtain estimates of the density */ kdensity lognorm, generate(dens) at(lognorm) nograph sort lognorm twoway (line dens lognorm if lognorm <= 5, lpattern(dash)) (line pdfx lognorm if lognorm <= 5), /// ytitle(Density) legend(order(1 "Kernel Density Estimate" 2 "Lognormal pdf")) **** Thanks again to both of you. Regards, Rebecca On Fri, May 31, 2013 at 1:13 PM, Nick Cox <njcoxstata@gmail.com> wrote: > I guess you'll need to -generate- the density and the corresponding > variable values, then re-graph. > > Nick > njcoxstata@gmail.com > > > On 31 May 2013 17:15, Rebecca Pope <rebecca.a.pope@gmail.com> wrote: > >> As an add-on question, is there a way to "zoom in" on the lower end of >> the plot? If I use -if-, -kdensity- calculates the density over that >> range (which I don't want). >> To see this: >> kdensity lognorm if lognorm<=10, addplot((kdensity lognorm if >> lognorm<=5, lpattern(dash))) /// >> legend(order(1 "Default Plot" 2 "Added Plot")) name(plot2) >> >> You'll notice that the greatest change is in Default Plot. >> >> If I use the x-axis options, it just changes the labeling without >> excluding the higher values of X. >> >> I'm running Stata 12.1 on Windows 7. Stata is updated to 20 Mar 13 & >> when I checked for updates, nothing new showed up. > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: strange kdensity behavior***From:*Rebecca Pope <rebecca.a.pope@gmail.com>

**Re: st: strange kdensity behavior***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: Random coefficients model** - Next by Date:
**st: To: statalist@hsphsun2.harvard.edu** - Previous by thread:
**Re: st: strange kdensity behavior** - Next by thread:
**st: Request regarding conversion of Stata code** - Index(es):