Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: backward incompatibility of -normden- for -normalden-


From   annoporci <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: backward incompatibility of -normden- for -normalden-
Date   Thu, 10 Jan 2013 08:46:01 +0800

Dear Statalist,

I have discovered that the old form of -normalden- named -normden- is
somewhat deprecated.

In a Satalist exchange dating back to 2004, Vince Wiggins of StataCorp
showed how to superimpose vertical density line plots for the distribution
of the disturbances on a regression line. I thought it was very nice and
wanted to reproduce it.

http://www.stata.com/statalist/archive/2004-07/msg00476.html

But it didn't work as written. The code stopped working from Stata 10
(i.e. if I copy the code as written in the cited url, it will work with
the "version 9" statement added before it but not otherwise).

The problem is caused by the old command -normden-

By replacing -normden- by -normalden- the code works in Stata 10,11,12.

As can be seen from the code I copy below, it is only inside the -range()-
expression that the problem with old form exists, elsewhere -normden-
still works.

I'm posting this for the record because it took me a while to understand
what the problem was.

The error message had some clues:

unknown function normden()
option range() requires two numbers

but as I was under the impression that -normden- was a short form of
-normalden- (like -gen- is a short form of -generate-), I assumed the
problem must be with the quotes around the arguments of -range-. When I
googled for -normden- I was directed to a lot of code that uses it, so I
did not suspect that the problem could be there. And when I cut off the
range() from the code, it worked despite the presence of other instances
of -normden- I therefore spent some time testing whether the quotes had
problems.

It's only after being directed to a passage in Nick Cox's article, that
the meaning of "unknown function normden()" hit me. Nick writes: "In Stata
9, normalden() is the name for the function previously called normden()".

There is no mention of the old name -normden- on the Stata help page for
-normalden-.

--
Patrick Toche.

A1  - Cox, N. J.
TI  - Speaking Stata: Density probability plots
JF  - Stata Journal
PB  - Stata Press
CY  - College Station, TX
Y1  - 2005
UR  - http://www.stata-journal.com/article.html?article=gr0012



clear all
sysuse auto
keep if foreign
sort weight

gen weight2 = weight^2
regress mpg weight weight2
predict fit
predict se, stdp

/// original code by Vince Wiggins
/// http://www.stata.com/statalist/archive/2004-07/msg00476.html

#delimit ;
twoway sc mpg weight , pstyle(p3) ms(o)
	||
		fn weight[3]  - 1000 * normden(x, `=fit[3]' , `=se[3]')
		, range(`=fit[3]-5' `=fit[3]+5') horiz pstyle(p1)
	||
		fn `=fit[3]' , range(`=weight[3]' `=weight[3]-1000*normalden(0,0,
se[3])') pstyle(p1)
	||
		fn weight[17] - 1000 * normden(x, `=fit[17]', `=se[17]')
		, range(`=fit[17]-5' `=fit[17]+5') horiz pstyle(p1)
	||
		fn `=fit[17]', range(`=weight[17]' `=weight[17]-1000*normalden(0,0,
se[17])') pstyle(p1)
	||
		fn weight[21] - 1000 * normden(x, `=fit[21]' , `=se[21]')
		, range(`=fit[21]-7' `=fit[21]+7') horiz pstyle(p1)
	||
		fn `=fit[21]', range(`=weight[21]' `=weight[21]-1000*normalden(0,0,
se[21])') pstyle(p1)
	||
		line fit weight
	, clwidth(*2)
	legend(off)
	ytitle("Miles per gallon")
	xtitle("Weight")
	title("Scatter with Regression Line and Confidence Interval Densities",
size(4.8) margin(t=0 b=1.5) span)
; #delimit cr
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index