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: loop does not load file as stated


From   Jin-Hyun Bae <[email protected]>
To   [email protected]
Subject   st: loop does not load file as stated
Date   Fri, 2 Aug 2013 12:49:26 -0400

Hello!

I have two levels of loops below. The top level cycles through years.
Within this loop, the file Distance.dta is loaded, and then all drops
all irrelevant year observations are dropped. When the second level
loops have finished running, it should save this file as "year".dta
and clear all.

I think every time that the first loop goes back to the beginning the
Distance.dta should be the same because I have not asked for any
changes to be saved to Distance.dta. But when I run this code, it
looks like all the observations that were dropped in the earlier loop
remained dropped.

I am almost certain that there is a simple explanation for this but I
am completely baffled!!

Jin

--------------

forvalues y = 1970/2004{
	use Distance.dta, clear
 	keep if Year == `y'
	gsort -usa	
	local N = _N
	matrix V1 = (POLCON[1] \ WBgovexp[1] \ WBdomcred[1])
	matrix rownames V1 = "POLCON WBgovexp WBdomcred"
	forvalues i = 2/`N'{
		matrix V`i' = (POLCON[`i'] \ WBgovexp[`i'] \ WBdomcred[`i'])
		matrix rownames V`i' = "POLCON WBgovexp WBdomcred"
		mahascore2 POLCON WBgovexp WBdomcred, point1(V1) point2(V`i')
covarpop(one) compute
		replace poldist = r(mahascore_sq) in `i'
		}
		matrix drop _all

	matrix V1 = (WBpcGDP[1] \ Wbinfln[1] \ WBX[1] \ WBM[1])
	matrix rownames V1 = "WBpcGDP Wbinfln WBX WBM"
	forvalues i = 2/`N'{
		matrix V`i' = (WBpcGDP[`i'] \ Wbinfln[`i'] \ WBX[`i'] \ WBM[`i'])
		matrix rownames V`i' = "WBpcGDP Wbinfln WBX WBM"
		mahascore2 WBpcGDP Wbinfln WBX WBM, point1(V1) point2(V`i')
covarpop(one) compute
		replace econdist = r(mahascore_sq) in `i'
		}
	matrix drop _all

	matrix V1 = (Power[1] \ Uncert[1] \ Indlm[1] \ Masc[1] \ Relig[1])
	matrix rownames V1 = "Power Uncert Indlm Masc Relig"
	forvalues i = 2/`N'{
		matrix V`i' = (Power[`i'] \ Uncert[`i'] \ Indlm[`i'] \ Masc[`i'] \ Relig[`i'])
		matrix rownames V`i' = "Power Uncert Indlm Masc Relig"
		mahascore2 Power Uncert Indlm Masc Relig, point1(V1) point2(V`i')
covarpop(one) compute
		replace cultdist = r(mahascore_sq) in `i'
		}
	matrix drop _all
	saveold `y'.dta, replace
}
*
*   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