Statalist


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

st: Re: looping with vars across file


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: Re: looping with vars across file
Date   Sat, 11 Oct 2008 14:43:08 +0200

To expand on that:


**********
*clear mem
clear*
ma drop _all

*create fancy new dataset
sysuse auto, clear
drop in -30/l
save autonew, replace

*determine variables amenable to this analysis and store them and their levels in -local-s
sysuse auto, clear
ds, has(type numeric)
loc variables `r(varlist)'
qui foreach var of loc variables{
levelsof `var', loc(levof`var')
}

*do whatever you want in second dataset
u autonew, clear
foreach var of loc variables{
di _n(2) in red "Currently at variable `var'" _n(2) "Levels of `var':" _n
foreach lev of loc levof`var'{

<put your analysis in terms of `lev' in here>

}
}

**********

HTH
Martin
_______________________
----- Original Message ----- From: "mai7777" <[email protected]>
To: <[email protected]>
Sent: Saturday, October 11, 2008 8:44 AM
Subject: st: looping with vars across file


Hi,
I have two files, file 1 and file 2. I want to use each var (one by
one) from file 1 to run a loop in file 2.
Eg:

File one:
var1  var2....varn
101    99       .
76     104     .
89     107     .

I want to run a loop in file two that takes each value for vars1-varn
in file 1 and loops over it: So for var1 of file1, I want to run the
following loop in file2:
foreach i in `i' 101 76 89 {
......
}

and so on for each var of file 1.
Is there a way to do that?

*
*   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/



*
*   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/



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