Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Some basic help on programming
From
Prakash Singh <[email protected]>
To
[email protected]
Subject
Re: st: Some basic help on programming
Date
Sat, 14 Apr 2012 23:14:04 +0530
Dear Friedrich,
Though, I am reading materials to learn programming but I am finding
it little tricky thus forced to ask probably this stupid query.
I was wondering what should be the command for creating local in case
I want to let stata read more than two levels of data in the
programme code you provided me the last mail. the codes I have pasted
below for ease.
local levels "3 4"
foreach l of local levels {
use "level`l'_list.dta", clear
local vars "item_code asicc_code unit_quantity quantity value"
levelsof item_code, local(items)
foreach i of local items {
preserve
keep if item_code==`i'
foreach var of varlist `vars' {
ren `var' `var'_`i'
}
sort common_id
save "item`i'.dta", replace
restore
}
contract common_id
drop _freq
foreach i of local items {
merge common_id using "item`i'.dta"
drop _merge
sort common_id
}
save "level`l'data.dta"
}
use "level3data.dta"
merge common_id using "level4data.dta"
Thanks
Prakash
*
* 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/