Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: Some basic help on programming

From   Prakash Singh <>
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 {
   keep if item_code==`i'
   foreach var of varlist `vars' {
     ren `var' `var'_`i'
   sort common_id
   save "item`i'.dta", replace
 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"

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index