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   Fri, 13 Apr 2012 00:06:07 +0530

Thanks Friedrich

This will reduce a great deal of boring job of making long do file
with keep if, save,use and merge .


Prakash
On Thu, Apr 12, 2012 at 11:26 PM, Friedrich Huebler <[email protected]> wrote:
> Prakash,
>
> You want to "merge all the 28 item wise file in stead of merging 10
> file separately 18 file separately and then merging these two to get
> the final data." There may be a way to do so but it is also possible
> to minimize the lines of code by adding another loop. Assume that you
> have two datasets, level3_list.dta and level4_list.dta. You can
> process both files by creating a loop that refers to the numbers 3 and
> 4. The converted datasets are subsequently merged.
>
> Friedrich
>
>
> 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"
>
>
> On Thu, Apr 12, 2012 at 10:24 AM, Prakash Singh <[email protected]> wrote:
>> Friedrich, I am really sorry for this inconvenience and ignorance
>>
>> In continuation to my earlier question that the data set I am
>> referring contains item number in each level. with you proggraming
>> help what I could do was breaking the level data at item number wise
>> and them merging it back.
>>
>> Now, suppose that I want to do the same for two different level data
>> and then merge all the data created at item number basis at once.
>>
>> for example level3 data has item number from 309 to 319 so we get 10
>> data at item number and merged it. Level4 data contains item number
>> 321-238, i.e. 18 item data  file to merge for level4. But how to do
>> this combined for level3 and level4 item number data. I mean is there
>> possibility to extend the programmee to break the level data for both
>> the level data and merge all the 28 item wise file in stead of merging
>> 10 file separately  18 file separately and then merging these two to
>> get the final data.
>>
>>
>> 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/

*
*   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