Bookmark and Share

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   Mon, 16 Apr 2012 17:53:04 +0530

Friedrich,
I know that there is some thing worng with my code. when I am merging
the level data ie last part of the code but what ever changes I have
tried some or the other error is coming.

Here is the code

local levels "3 4 5 6 7 8 9"
foreach l of local levels {
 use "level`l'_list.dta", clear
 if level==3 | level==5 {
 local vars "item_code asicc_code unit_quantity quantity value"
 }
 if level==4| level ==6| level==7 {
 local vars "item_code value"
 }
 if level==8 {
 local vars "item_code value_ownd_assets value_hired_assets
addition_ownd_assets sign rent_payable"
 }
 if level==9 {
 local vars "item_code loan_outs int_payable"
 }
 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",replace
}
contract common_id
 drop _freq
 foreach l of local levels {
   merge common_id using "level`l'data.dta"
   drop _merge
   sort common_id
 }
save "level3_9data.dta",replace



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/


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