Joseph Coveney has illustrated a way of
doing this. Here is a slightly more
Stataish version of that:
use auto.dta, clear
ologit rep78 price turn
forval j = 1/`e(k_cat)' {
tempvar pre
local prelist "`prelist' `pre'"
}
predict `prelist'
Here there is no need to initialise
the macro prelist, which is born empty.
(That would not be true if it had been
used earlier in the same program.)
Also, if you say
tempvar pre
Stata is not fussed if you said that
previously. `pre' will always refer
to the last temporary variable defined
in that way. Naturally, you need to keep track
of previous names, but that is what is being done here.
Nick
[email protected]
Mike Lacy
> 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 .
>
> Example:
>
> use auto.dta
> ologit rep78 price turn
> local k = `e(k_cat)' /* save for future use
> local ptop = "p`k'"
> predict p1-`ptop'
>
> This works fine, but what I would really like is to
> get the predicted probabilities into a list of *tempvars.*
> tempvar p1-`ptop'
> is apparently not legal syntax.
>
> So, I put all the the p1, ..., pk into a local macro, say plist,
> using run time information about k, so I get plist = "p1 p2 p3 ... pk"
>
> Then, I find that
> tempvar `plist'
> creates the list of temporary variables as desired,
> but then I can't figure how to use `plist' to -predict-
> the list of probabilities into the tempvars in plist.
>
> So, what would be recommended as a way to get
> a vector of predicted probabilities into a
> list of tempvars? Perhaps my `plist' *can* be used?
>
*
* 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/