[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Friedrich Huebler" <fhuebler@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Loop over variables with svyset |

Date |
Fri, 21 Nov 2008 11:33:04 -0500 |

Daniel, Your previous message did not state that you had a "variable not found" error. Section 3.3 of the Statalist FAQ advises: "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly! If you can, reproduce the error with one of Stata's provided datasets or a simple concocted dataset that you include in your posting." Does your loop produce the variable names that you need? You can check by adding -display- commands to the loop, as I suggested in my last message. display "`k'" display "Q1170_0`year'" display "Q0`k'_0`year'" You can also use -confirm- in combination with -capture- to execute commands only for variables that exist in your data. sysuse auto, clear foreach var in mpg weight xyz { capture confirm variable `var' if !_rc { sum `var' } } Friedrich On Fri, Nov 21, 2008 at 6:35 AM, Daniel Schultz <schultzd@tcd.ie> wrote: > Sorry for not mention the error. > I thought that the error message is clear, due to my description. > The error message is, that a variable is not found. This is due to the > fact, that I don't have every variable for every year. Which is the > reason why I need a loop like the one Steven posted. But which shows > respect to the fact, that some variables are missing. (concerning the > year). > > Hope this was explanation enough. > > 2008/11/19 Friedrich Huebler <fhuebler@gmail.com>: >> Daniel, >> >> First, you don't say which error you encounter. Please elaborate. >> Second, you can include a -di- command in your loop to check if the >> values of k are the values you need. >> >> capture { >> forvalues k=1/3 { >> if `k' < 100 local k 0`k' >> if `k' < 10 local k 0`k' >> di "k = `k'" >> etc. >> >> Friedrich >> >> On Wed, Nov 19, 2008 at 12:57 PM, Daniel Schultz <schultzd@tcd.ie> wrote: >>> Ok thanks for all the comments... >>> with the -capture block the do-file is running, >>> BUT >>> is actually producing no output after the first error. >>> This is the part of my do-file (to make it more quick only until Number 3) >>> >>> capture { >>> forvalues k=1/3{ >>> if `k' < 100 local k 0`k' >>> if `k' < 10 local k 0`k' >>> forvalues year=2/7 { >>> svyset [pw=Q1170_0`year'] >>> svy: tab Q0`k'_0`year' >>> mat Q0`k'_0`year' = (e(Prop)\e(total)) >>> } >>> } >>> } >>> >>> The first error occurs after the first run of the second forvalues >>> (forvalues year=2/7 {) loop (number 3). >>> With the capture block, the do-file is working, but the mat command >>> only produces a matrix until the first error (a matrix only for year >>> =2). Thus, I assume, that it is not working totally. >>> >>> With adding -noisily the do file stops when the first error occurs. >>> Best >>> Daniel >>> >>> >>> 2008/11/19 Buzz Burhans <buzzb3@verizon.net>: >>>> server >>>> >>>> Steve wrote >>>> "Just be aware that captured statements, whether they produce errors >>>> or not, show no output." >>>> >>>> >>>> -capture noisily { >>>> ... >>>> }- >>>> >>>> will produce output if the command does not fail and would otherwise produce >>>> output. >>>> >>>> So capture, with noisily added, should give you output, unless the command >>>> fails >>>> >>>> Buzz Burhans * * 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/

**References**:**Re: st: Loop over variables with svyset***From:*Steven Samuels <sjhsamuels@earthlink.net>

**RE: st: Loop over variables with svyset***From:*"Buzz Burhans" <buzzb3@verizon.net>

**Re: st: Loop over variables with svyset***From:*"Daniel Schultz" <schultzd@tcd.ie>

**Re: st: Loop over variables with svyset***From:*"Friedrich Huebler" <fhuebler@gmail.com>

**Re: st: Loop over variables with svyset***From:*"Daniel Schultz" <schultzd@tcd.ie>

- Prev by Date:
**st: RE: specifying range in forvalues** - Next by Date:
**st: svy and pweight postestimation tools** - Previous by thread:
**Re: st: Loop over variables with svyset** - Next by thread:
**st: GEE and likelihood ratio test** - Index(es):

© Copyright 1996–2019 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |