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

st: Re: no observation in while-loop

From   "Martin Weiss" <>
To   <>
Subject   st: Re: no observation in while-loop
Date   Fri, 19 Jun 2009 21:05:10 +0200


Maybe like this:

u DataBase, clear

su id, mean
forv i=1/`r(max)'{
capt reg machines import if id==`i'
capt predict machfilled`i' if e(sample)

save A, replace

----- Original Message ----- From: "Martin Baumgarten" <>
To: <>
Sent: Friday, June 19, 2009 8:51 PM
Subject: st: no observation in while-loop


I have a panel with 148 countries (id) over 30 years (time).
I need fitted values for one of the variables therefore I created this while loop

local i=1
while `i'<=148 {
use DataBase.dta
keep if id==`i'
reg machines import
predict machfilled
save A`i'
local i=`i'+1

However, for some countries, there is no data available and the loop stops. Then Stata returns "no observations".

Is there a way to skip these countries without observations? So that the loop will not be interrupted.

Thank for your help

m. baumgarten
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter
*   For searches and help try:

*   For searches and help try:

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