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]

Re: st: loop does not load file as stated


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: loop does not load file as stated
Date   Fri, 2 Aug 2013 13:43:11 -0400

Q2: add after use and before keep:
count
count if Year==`y'
How many observations are dropped?

You have four loops: y,i1,i2,i3 where is the problem you are looking for?
I would just comment out with /* */ everything dealing with the
matrices (after keep) until saveold and see what gets saved.

NB: matrix drop _all is generally a bad idea. It looks harmless now,
but once you or somebody else is calling this do file from her own
do-file with her own matrices, you will do some damage to her
matrices.

Best, Sergiy


On Fri, Aug 2, 2013 at 1:07 PM, Jin-Hyun Bae <[email protected]> wrote:
> I did as you said, but Stata didn't fail on any line. It just ran
> through. Still have the same problem though.
>
> Looking at the results, the only weird thing happening is that the
> third loop isn't working. It isn't producing estimates (or outputting
> them)...
>
> But, the code I have been using for that loop is equivalent to the
> other code doing essentially the same thing but with different
> variables.
> ----------------------
>
> set a read-only flag on the data file in the OS, and rerun. Then see
> the line which fails in Stata.
>
> On Fri, Aug 2, 2013 at 12:49 PM, Jin-Hyun Bae <[email protected]> wrote:
>> 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/
> *
> *   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/
> *
> *   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/
*
*   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