Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: double loop issue

From   Molly Lipscomb <>
Subject   st: Re: double loop issue
Date   Mon, 19 Feb 2007 10:15:00 -0800 (PST)

Thanks for your suggestions, I guess I wasn't as clear
as I meant to be.

The reason that I am renaming and merging the file in
so many times is that I need distance weighted
averages of about 150 variables over 55 counties for
each observation.  This would make the matrix size
much too large if I tried to do it in a single
command, so I am trying to use a look and use running
sums of each of the variables.

Here is the actual code that I was using (with some of
the variables in the loop removed to reduce space):

forvalues p=1/55 {
use C:\Brazil\Munisplits\mergingdata.dta
foreach var in capital_spending1990
health_sanitation_spending1990 investment1990
transfers1990 assessed_municipal_share1990 plus more
variables  {
ren `var' `var'_`p'
ren muni muni`p'
sort muni`p'
save C:\Brazil\Munisplits\averagesloop.dta, replace
use C:\Brazil\Munisplits\root.dta
sort muni`p'
merge muni`p' using
tab _merge
drop if _merge==2
drop _merge
replace `var'_r=`var'_r+`var'_`p'*routelength`p' if
`var'_`p'!=. & routelength`p'!=.
replace `var'_d=`var'_d+routelength`p' if `var'_`p'!=.
& routelength`p'!=.

save C:\Brazil\Munisplits\root.dta, replace


The fish are biting.
Get more visitors on your site using Yahoo! Search Marketing.
*   For searches and help try:

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