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: Tempfile in double loop for correlations


From   Peggy Fan <[email protected]>
To   [email protected]
Subject   st: Tempfile in double loop for correlations
Date   Wed, 3 Jul 2013 21:15:42 -0700 (PDT)

Hi, 

I wish to save the correlations between two sets of variables.
Set 1: statism modernity postmodernity student
Set 2: histonly soc_oth civonly 

I want to save a tempfile for the correlations between statism:set 2 variables, another tempfile for modernity:set2 variables, so forth. So I want to save and outsheet 4 tempfiles.

I am running the following codes successfully-

foreach k in statism modernity postmodernity student {
foreach var of varlist histonly soc_oth civonly {

quietly corr `k' `var'
di as text "`: variable label `var'':   " as result r(rho)
     }
}


But I'm having trouble saving the results in tempfiles. I played around with different parts of the code but kept getting error messages. This is an example of what I think should work-

foreach k in statism modernity postmodernity student {

tempname memhold
tempfile results`k'
postfile `memhold' statism modernity postmodernity student rho using `results`k'', replace

foreach var of varlist histonly soc_oth civonly {
quietly corr `k' `var'
local `k'_`var' = e(rho)
di `rho'
post `memhold' ("`k'") (`rho') 
  } 
postclose `memhold'
}


Error comes up:
type mismatch

When I try to outsheet the data

use `results`k'', clear

Error is: invalid specified file.


Any other suggestions to how to capture those correlation coefficients are welcome.
*
*   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