Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Friedrich Huebler <fhuebler@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Some basic help on programming |
Date | Sun, 15 Apr 2012 18:55:29 -0400 |
Prakash, You should have enough information to find the solution yourself. Previously, you worked with two files, level3_list.dta and level4_list.dta. The numbers 3 and 4 occur at the beginning and end of the code I provided. Now assume you add level5_list.dta. I indicate below where you have to change the code. local levels "3 4" <-- Change this command by adding the number 5 [leave remaining commands unchanged] drop _merge <-- Add this because you merge more than two sets of data. See -help merge- for more information. merge common_id using "level4data.dta" <-- Repeat the last command from the original code but change 4 to 5. Repeat the above if you want to add levels 6, 7 and so on. Friedrich On Sat, Apr 14, 2012 at 1:44 PM, Prakash Singh <prakashbhu@gmail.com> wrote: > 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/