| ![]() |
From | Kit Baum <baum@bc.edu> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: creating loops to drop observations |
Date | Mon, 3 Apr 2006 07:31:45 -0400 |
Although in this example forval may be more appropriate...Assuming that code is always countryN then you could...use dataset.dta, clear drop if code=="country1" regress y x use dataset.dta, clear drop if code=="country2" regress y x
forval x = 1/N{
use dataset, clear
drop if(code == "country`x'")
regress y x
}
You would substitute N in the above for the maximum country number.
If however you actually have named countries such as "Australia",
"United States", "Germany", "Nepal", "United Kingdom", "France" etc.
then you would have to use foreach....
foreach x in Australia "United States" France Germany "United Kingdom" Nepal{
use dataset, clear
drop if(code == "`x'")
regress y x
}
* * 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–2025 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |