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: RE: __000001 not found error in macro loop


From   Fiona Feng <[email protected]>
To   [email protected]
Subject   Re: st: RE: __000001 not found error in macro loop
Date   Sat, 23 Jul 2011 14:48:49 +1000

Hi Nick,

Yes you were right about the syntax, thanks anyway Jesper. I've worked
out that the code:

egen double flows = sum(weight), by(lfs2)

Causes the code to for some reason delete all observations. Any idea
why that would be the case? In this case lfs2 is a string variable, so
all I'm generating is a new set of variables "flows" that sums the
"weight" of observations by lfs2. Is there anyway I can produce the
same result of this line of code without using egen or sum(weight)?
I'm pretty sure the problem's with one of these two commands.

Many thanks,

Fiona.

On Sat, Jul 23, 2011 at 12:07 AM, Nick Cox <[email protected]> wrote:
> I disagree. Fiona's -foreach- syntax is fine and in any case integers
> could never be variable names. Elsewhere I've made a guess at the
> problem.
>
> Nick
>
> On Fri, Jul 22, 2011 at 6:45 AM, Jesper Lindhardsen
> <[email protected]> wrote:
>> Hi Fiona!
>>
>> Have you tried
>>
>> foreach y of numlist 11 12 13 14 15 16 21 22 23 31 32 33 34 35 41 42 43
>> 44 45
>> 46 47 51 52 53 54 55 56 57 58 59 61 62 63 64 71 72 73 74 81 82 83 84
>> 85 86 87 88 91 92 93 94 95 {
>>
>> I think it may be to vague with "foreach y in 11 12 {" as Stata may
>> interpret these as variables. Hence the error message.
>>
>> HTH, Jesper
>>
>> Jesper Lindhardsen
>> MD, PhD candidate
>> Department of Cardiovascular Research
>> Copenhagen University Hospital, Gentofte
>> Denmark
>>
>>
>>
>>
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Fiona Feng
>> Sent: 22 July 2011 10:15
>> To: [email protected]
>> Subject: st: __000001 not found error in macro loop
>>
>> Hi all,
>>
>> I've got a pretty strange problem. I want to run some existing code by
>> region and by state, so I just added a line of code at the beginning
>> to run the program by region or by state. The problem is that while
>> the code by region works fine, the code for state gives a "__000001
>> not found" error. The code for region is:
>>
>> **2. match_flows
>> forvalues y=1/4 {
>> local x=197601
>>
>> while `x' <= 201012 {
>>
>>    quietly {
>>        if `x' != 197601 & `x' != 197801 & `x' != 198507 & `x' !=
>> 198510 & `x' != 199401 & `x' != 199506 & `x' != 199507 & `x' != 199508
>> & `x' != 199509 {
>>                use merg`x', clear
>>                save "merg`x'-`y'.dta", replace
>>                keep if reg==`y'
>>                keep if age >= 16
>>                *drop if mis0 == 1
>>                gen str1 lfs0 = "E" if status0 == 1 | status0 == 2
>>                replace lfs0 = "U" if status0 == 3
>>                replace lfs0 = "I" if status0 == 4 | status0 == 5 |
>> status0 == 6 | status0 == 7
>>                replace lfs0 = "U" if status0 == 4 & `x' > 198901
>>                replace lfs0 = "M" if lfs0 == ""
>>                gen str1 lfs1 = "E" if status1 == 1 | status1 == 2
>>                replace lfs1 = "U" if status1 == 3
>>                replace lfs1 = "I" if status1 == 4 | status1 == 5 |
>> status1 == 6 | status1 == 7
>>                replace lfs1 = "U" if status1 == 4 & `x' > 198900
>>                replace lfs1 = "M" if lfs1 == ""
>>
>>                gen str2 lfs2 = lfs0 + lfs1
>>
>>                sort lfs2
>>                replace fweight0 = 0 if fweight0 == .
>>                replace fweight1 = 0 if fweight1 == .
>>                gen weight = (fweight0+fweight1)/2
>>                egen double flows = sum(weight), by(lfs2)
>>                replace flows = flows/1000
>>                if `x' > 199400 {replace flows = flows/100}
>>
>>                sort lfs2
>>                quietly by lfs2:  gen duplic = cond(_N==1,0,_n)
>>                drop if duplic > 1
>>
>>                keep lfs2 flows reg
>>                gen date = `x'
>>                reshape wide flows, i(date) j(lfs2) string
>>
>>                gen flowEE = flowsEE/(flowsEE+flowsEI+flowsEU+flowsEM)
>>                gen flowEI = flowsEI/(flowsEE+flowsEI+flowsEU+flowsEM)
>>                gen flowEU = flowsEU/(flowsEE+flowsEI+flowsEU+flowsEM)
>>                gen flowEM = flowsEM/(flowsEE+flowsEI+flowsEU+flowsEM)
>>                gen flowUE = flowsUE/(flowsUE+flowsUI+flowsUU+flowsUM)
>>                gen flowUI = flowsUI/(flowsUE+flowsUI+flowsUU+flowsUM)
>>                gen flowUU = flowsUU/(flowsUE+flowsUI+flowsUU+flowsUM)
>>                gen flowUM = flowsUM/(flowsUE+flowsUI+flowsUU+flowsUM)
>>                gen flowIE = flowsIE/(flowsIE+flowsII+flowsIU+flowsIM)
>>                gen flowII = flowsII/(flowsIE+flowsII+flowsIU+flowsIM)
>>                gen flowIU = flowsIU/(flowsIE+flowsII+flowsIU+flowsIM)
>>                gen flowIM = flowsIM/(flowsIE+flowsII+flowsIU+flowsIM)
>>                gen flowME = flowsME/(flowsME+flowsMI+flowsMU)
>>                gen flowMI = flowsMI/(flowsME+flowsMI+flowsMU)
>>                gen flowMU = flowsMU/(flowsME+flowsMI+flowsMU)
>>                drop flows*
>>            }
>>
>>
>>            else {
>>            clear
>>            set obs 1
>>            gen date = `x'
>>            gen flowEE = .
>>            gen flowEI = .
>>            gen flowEU = .
>>            gen flowEM = .
>>            gen flowUE = .
>>            gen flowUU = .
>>            gen flowUI = .
>>            gen flowUM = .
>>            gen flowIE = .
>>            gen flowIU = .
>>            gen flowII = .
>>            gen flowIM = .
>>            gen flowME = .
>>            gen flowMU = .
>>            gen flowMI = .
>>            }
>>
>>            if `x' >= 197602 {
>>                append using flows`y'
>>            }
>>
>>            save "flows`y'.dta", replace
>>    }
>>
>>
>>    local x = `x' + 1
>>    if (`x'-13)/100 == int((`x'-13)/100) {
>>        local x = `x' + 88
>>        noisily display (`x'-1)/100}
>>            }
>>
>>        sort date
>>
>>        gen flowMM = 0
>>
>>        save "flows`y'.dta", replace
>>
>>
>> }
>>
>> While the code for state is:
>> **2. match_flows
>> foreach y in 11 12 13 14 15 16 21 22 23 31 32 33 34 35 41 42 43 44 45
>> 46 47 51 52 53 54 55 56 57 58 59 61 62 63 64 71 72 73 74 81 82 83 84
>> 85 86 87 88 91 92 93 94 95 {
>> local x=197601
>> while `x' <= 201012 {
>>            quietly {
>>            if `x' != 197601 & `x' != 197801 & `x' != 198507 & `x' !=
>> 198510 & `x' != 199401 & `x' != 199506 & `x' != 199507 & `x' != 199508
>> & `x' != 199509 {
>>                    use merg`x', clear
>>                    save "merg`x'-`y'.dta", replace
>>                    keep if state==`y'
>>                    keep if age >= 16
>>                    *drop if mis0 == 1
>>                    gen str1 lfs0 = "E" if status0 == 1 | status0 == 2
>>                    replace lfs0 = "U" if status0 == 3
>>                    replace lfs0 = "I" if status0 == 4 | status0 == 5
>> | status0 == 6 | status0 == 7
>>                    replace lfs0 = "U" if status0 == 4 & `x' > 198901
>>                    replace lfs0 = "M" if lfs0 == ""
>>                    gen str1 lfs1 = "E" if status1 == 1 | status1 == 2
>>                    replace lfs1 = "U" if status1 == 3
>>                    replace lfs1 = "I" if status1 == 4 | status1 == 5
>> | status1 == 6 | status1 == 7
>>                    replace lfs1 = "U" if status1 == 4 & `x' > 198900
>>                    replace lfs1 = "M" if lfs1 == ""
>>
>>                    gen str2 lfs2 = lfs0 + lfs1
>>
>>                    sort lfs2
>>                    replace fweight0 = 0 if fweight0 == .
>>                    replace fweight1 = 0 if fweight1 == .
>>                    gen weight = (fweight0+fweight1)/2
>>                    egen double flows = sum(weight), by(lfs2)
>>                    replace flows = flows/1000
>>                    if `x' > 199400 {replace flows = flows/100}
>>
>>                    sort lfs2
>>                    quietly by lfs2:  gen duplic = cond(_N==1,0,_n)
>>                    drop if duplic > 1
>>
>>                    keep lfs2 flows state
>>                    gen date = `x'
>>                    reshape wide flows, i(date) j(lfs2) string
>>
>>                    gen flowEE =
>> flowsEE/(flowsEE+flowsEI+flowsEU+flowsEM)
>>                    gen flowEI =
>> flowsEI/(flowsEE+flowsEI+flowsEU+flowsEM)
>>                    gen flowEU =
>> flowsEU/(flowsEE+flowsEI+flowsEU+flowsEM)
>>                    gen flowEM =
>> flowsEM/(flowsEE+flowsEI+flowsEU+flowsEM)
>>                    gen flowUE =
>> flowsUE/(flowsUE+flowsUI+flowsUU+flowsUM)
>>                    gen flowUI =
>> flowsUI/(flowsUE+flowsUI+flowsUU+flowsUM)
>>                    gen flowUU =
>> flowsUU/(flowsUE+flowsUI+flowsUU+flowsUM)
>>                    gen flowUM =
>> flowsUM/(flowsUE+flowsUI+flowsUU+flowsUM)
>>                    gen flowIE =
>> flowsIE/(flowsIE+flowsII+flowsIU+flowsIM)
>>                    gen flowII =
>> flowsII/(flowsIE+flowsII+flowsIU+flowsIM)
>>                    gen flowIU =
>> flowsIU/(flowsIE+flowsII+flowsIU+flowsIM)
>>                    gen flowIM =
>> flowsIM/(flowsIE+flowsII+flowsIU+flowsIM)
>>                    gen flowME = flowsME/(flowsME+flowsMI+flowsMU)
>>                    gen flowMI = flowsMI/(flowsME+flowsMI+flowsMU)
>>                    gen flowMU = flowsMU/(flowsME+flowsMI+flowsMU)
>>                    drop flows*
>>                }
>>
>>
>>                else {
>>                clear
>>                set obs 1
>>                gen date = `x'
>>                gen flowEE = .
>>                gen flowEI = .
>>                gen flowEU = .
>>                gen flowEM = .
>>                gen flowUE = .
>>                gen flowUU = .
>>                gen flowUI = .
>>                gen flowUM = .
>>                gen flowIE = .
>>                gen flowIU = .
>>                gen flowII = .
>>                gen flowIM = .
>>                gen flowME = .
>>                gen flowMU = .
>>                gen flowMI = .
>>                }
>>
>>                if `x' >= 197602 {
>>                append using flows`y'
>>                }
>>
>>                save "flows`y'.dta", replace
>>        }
>>
>>
>>        local x = `x' + 1
>>        if (`x'-13)/100 == int((`x'-13)/100) {
>>            local x = `x' + 88
>>            noisily display (`x'-1)/100
>>            }
>>                }
>>
>>    sort date
>>
>>    gen flowMM = 0
>>
>>    save "flows`y'.dta", replace
>>
>>
>> }
>>
>> Considering that I've made very minor changes to the code, I don't see
>> what the problem is. Using the trace command, I've managed to deduce
>> that it's something to do with the egen code:
>>
>> egen double flows = sum(weight), by(lfs2)
>>
>> That causes the "__000001 not found" error.
>>
>> Please help!
>>
>> Many thanks,
>>
>> Fiona Feng.
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/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/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index