Mike Lacy wrote:
I am wanting to use -predict- after -ologit- to put the predicted
probabilities into a set of temporary variables. I think my questions may
bring up enough issues about using temporary variables so as to be of more
general interest.
Questions:
1) How to use -predict- to store values in a list of tempvars .
[Redacted]
2) Next, I have occasion to use these tempvars in loops.
[Redacted]
Clearly, I am missing some piece of understanding here as well.
I guess the question would be:
How to use a list of temporary variables in a loop if those temporary
variable do not yet have assigned values?
--------------------------------------------------------------------------------
Take a look at the following do-file and see whether it answers your questions.
Joseph Coveney
P.S. Consider using a descriptive subject line in your post.
tempvar tmpvar
sysuse auto, clear
ologit rep78 price turn
* Begin Question 1) here
local cat_max = e(k_cat)
local varlist = ""
forvalues i = 1/`cat_max' {
local varlist `varlist' `tmpvar'`i'
}
display "`varlist'"
predict `varlist'
* End Question 1)--Begin Question 2) here
generate float latent_var = uniform()
foreach var of varlist `varlist' {
generate byte sco_`var' = (latent_var > `var')
}
egen byte sco = rsum(sco_*)
slist _* sco_* sco, noobs
exit
*
* 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/