Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Urgent: Saving Coefficient


From   Roger Newson <[email protected]>
To   [email protected]
Subject   RE: st: Urgent: Saving Coefficient
Date   Thu, 25 Mar 2004 21:26:23 +0000

At 16:11 25/03/04 -0500, Dev Vencappa wrote:
Thanks a lot for your help. The loop ran for a few observation this time but stopped again saying "insufficient observations". Obviously, it stopped because of unability to run the regression with too few observations. Is there any way to make it ignore insufficient numbers and complete the loop?

This looks like a possible job for -parmby-, which is part of the -parmest- package, downloadable from SSC. -parmby- is programmed only to fail if the regression command fails for all by-groups, and will complete without error if the regression command only fails for some by-groups.

I hope this helps.

Roger


----- Original Message -----
From: "Nick Cox" <[email protected]>
Date: Thu, 25 Mar 2004 10:36:16 -0000
To: <[email protected]>
Subject: RE: st: Urgent: Saving Coefficient

> (Apologies for previous premature post.)
>
> You could identify the problematic
> observations upstream and ignore
> them systematically. Also the -regress-
> must be on subsets for this to make sense.
>
> use data
> gen coeff = .
> egen nmiss = rmiss(gdp year)
> encode countrycode if nmiss == 0, gen(id)
> su id, meanonly
>
> qui forval i = 1/`r(max)' {
>       reg gdp year if id == `i'
>       replace coeff=_b[year] if id == `i'
> }
>
> Note also -statsby-.
>
> Nick
> [email protected]
>
> Dev Vencappa
> >
> > Thank a lot Dev. But I ran into a rather weird problem while
> > applying it to real data. It seems that the loop abruptly
> > stops whenever their are  missing values for variables used
> > in the regression. In my case, the data starts with e.g. BAN
> > and gdp for BAN is all missing like this:
> >
> > Country Code        Year    GDP
> >  BAN                1960    .
> >  BAN                1965    .
> >  BAN                1970    .
> >
> >
> > The loop does not produce any result and gives "no
> > observation" and just stops.
> >
> > Any suggestions?
> >
> > Kakatua
> > I tired with some fake data where I had missing values for a
> > variable and could not replicate this problem . But try to
> > add an extra condition in the loop, which is to ignore
> > observations that  have missing values for GDP. Therefore,
> > your new loop would be:
> >
> >  use data
> >  sort countrycode year
> >  encode countrycode,gen(id)
> >  tsset id year
> >  gen coeff=.
> >  forv id=1/2 {
> >  reg gdp year
> >  replace coeff=_b[year] if id==`id' & gdp!=.
> >  }
> >
> > Give that a try.
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
  or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]
Website: http://www.kcl-phs.org.uk/rogernewson

Opinions expressed are those of the author, not the institution.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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