I wrote:
Take a look at the following do-file and see whether it answers your questions.
--------------------------------------------------------------------------------
Sorry; when you change the name of a temporary variable, it's no longer
temporary, although if you -reshape long- after appending numbers as in the
first question's answer, it reverts to the original tempvar name and to being
temporary.
The same kind of list-building exercise that was illustrated in the do-file can
be used, however, to build the list of temporary variables, as illustrated
below in the revised do-file.
Joseph Coveney
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'
}
tempvar `varlist'
local varlist = char(96) + subinstr("`varlist'", " ", char(39)+ " " +
char(96), .) + char(39)
display "`varlist'"
predict `varlist' // These are tempvars and will disappear
// after exiting the do-file.
* End Question 1)--Begin Question 2) here
generate float latent_var = uniform()
foreach var of varlist `varlist' {
// The following are not tempvars and will
// remain afterward (after exiting from do-file),
// although the same technique above
// can be used here to make tempvars
// for these, too.
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/