| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: replacing a list of values within a loop
STATA lister's--
i currently have 4 datasets containing teacher id's (var: teacherX).
many teacher id's have been incorrectly entered and i would like to
replace them with the correct values. for each dataset, i have
identified 2 lists:
1) list of BAD teacher id's;
2) list of GOOD teacher id's, to replace 1.
i am wondering if these lists of values can somehow be incorporated in a
"forvalues" loop? can i assign the values as a scalar? my anticipated
coding is attached below. where "list of values" is written is where i
hope a minor miracle will occur.
many thanks for any suggestions,
--matthew
/************************/
local data1 "G3M"
local data2 "G3R"
local data3 "G8M"
local data4 "G8R"
// datafiles
local good1 "list of values"
local good2 "list of values"
local good3 "list of values"
local good4 "list of values"
// acceptable values
local bad1 "list of values"
local bad2 "list of values"
local bad3 "list of values"
local bad4 "list of values"
// rejected values
forvalues i = 1/4 {
log using "C:/`data`i''_FixTeacher.txt", replace text
use "C:/`data`i''.dta", clear
replace teacherX==`good`i'' if (teacherX==`bad`i'')
// replace bad values with good values
save "C:/`data`i''_Clean.dta", replace
}
/************************/
matthew m. gushta -- research associate
computer & statistical sciences center
american institutes for research
[email protected] -- 202.403.5079
*
* 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/