Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Bizarre praccum behavior


From   "Biernbaum, Lee" <[email protected]>
To   <[email protected]>
Subject   st: Bizarre praccum behavior
Date   Thu, 5 Jul 2007 17:53:01 -0400

I have encountered a un-intuitive error when using -praccum- on Stata 9,
a command built into the highly useful spost package (specifically,
spost9_ado, updated 4 June 2007, from Long and Freese's Indiana
University website and paired with the excellent "Regression Models for
Categorical Dependent Variables Using Stata" from Stata Press)

This command allows one to "accumulate" the various predictions
generated by running multiple -prvalue- commands, each designed to come
up with the predicted probability of y=#|x. The final time one
implements -praccum-, the option -using(matname) gen(varname)- is
included in order to generate a series of variables from the matrices
-matname- useful for analysis and plotting (e.g. pr(y=0|x=1,2,3,etc.),
pr(y=1|x=1,2,3,etc). Pretty nifty, eh?

I have written a -forvalues- loop in order to run -praccum- for a series
of values. After the loop terminates, I can run the command once more,
with the -gen- option and it works fine (see code 1).

However, I want to run the same loop with three different output sets
(that is, the run x=1,2,3,etc over a few different variables). The
situation for all three times is quite similar, so one loop seemed like
a good idea (so, yes, I know I can copy/paste in my .do file and, but I
want to get this right). The -praccum- runs in the loop fine, creating
the three desired matrices. However, after exiting the loop, it will
only create the variables via the -gen- command for the first -praccum-
listed. It quits with a "type mismatch r(109)" upon the second call. If
the data types were right on the 1st call, why wouldn't they be on the
2nd?

The order that I run them in does not matter, it only works for the
first 1 (see code 2).

In my case, I am using these commands following -nbreg-. Any ideas would
be appreciated.


*****CODE 1*******
forvalues counter = 0(1)15 {
	local cc2 = `counter' ^ 2
	local gc2 = `counter' ^ 2
	local ic2 = `counter' ^ 2
	qui: sum curve_count 
	local c_c = r(mean)
	qui: sum intersect_count
	local i_c = r(mean)
	qui: sum grade_count
	local g_c = r(mean)
	qui: sum lnmvmt
	local m_c = r(mean)

	local ci_c = `counter' * `i_c'
	local cg_c = `counter' * `g_c'

	local mc_c = `counter' * `m_c'

	qui: prvalue, x(curve_count = `counter' curve_count_sq = `cc2'
ci = `ci_c' cg = `cg_c' mc = `mc_c') rest(mean) 
	praccum, using(mat_cc) xis(`counter')
}

praccum, using(mat_cc) gen(p_cc)

******CODE 2******
***I am aware there is serious repetition in the local macros, it is
intended for clarity****

forvalues counter = 0(1)15 {
	local cc2 = `counter' ^ 2
	local gc2 = `counter' ^ 2
	local ic2 = `counter' ^ 2
	qui: sum curve_count 
	local c_c = r(mean)
	qui: sum intersect_count
	local i_c = r(mean)
	qui: sum grade_count
	local g_c = r(mean)
	qui: sum lnmvmt
	local m_c = r(mean)

	local ci_c = `counter' * `i_c'
	local gi_g = `counter' * `i_c'
	local cg_c = `counter' * `g_c'
	local cg_g = `counter' * `c_c'
	local ci_i = `counter' * `c_c'
	local gi_i = `counter' * `g_c'

	local mc_c = `counter' * `m_c'
	local mg_g = `counter' * `m_c'
	local mi_i = `counter' * `m_c'

	qui: prvalue, x(curve_count = `counter' curve_count_sq = `cc2'
ci = `ci_c' cg = `cg_c' mc = `mc_c') rest(mean) 
	praccum, using(mat_cc) xis(`counter')

	qui: prvalue, x(grade_count = `counter' grade_count_sq = `gc2'
gi = `gi_g' cg = `cg_g' mg = `mg_g') rest(mean)
	praccum, using(mat_gc) xis(`counter')

	qui: prvalue, x(intersect_count = `counter' intersect_count_sq =
`ic2' ci = `ci_i' gi = `gi_i' mi = `mi_i') rest(mean)
	praccum, using(mat_ic) xis(`counter')
}

praccum, using(mat_cc) gen(p_cc)
praccum, using(mat_gc) gen(p_gc)
praccum, using(mat_ic) gen(p_ic)
****** End CODE 2 *******
Note1: The program dies when running the 2nd to last line with the
error:
	type mismatch
	r(109);
Note2: the order of the final three lines does not matter. It always
exits in the 2nd to last
Note3: -matrix list mat_cc- (or mat_gc or mat_ic) contain the desired
output, so I know that is not the issue. If necessary, I could save
these matrices to variables but given that the command is supposed to do
(spost.ado, har har) that already, it would be nice if this could be
figured out.

Thanks,

Lee Biernbaum
Economic and Industry Analysis Division
US DOT, Volpe Center

(617) 494-2834
[email protected]


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index