Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Some basic help on programming


From   Prakash Singh <prakashbhu@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Some basic help on programming
Date   Mon, 16 Apr 2012 11:32:14 +0530

Friedrich

I could make necessary changes in the programme for most of the part
and in fact I could run it successfully but later on I thought why we
can't merge level`l'data the way item`i' data is merged and that's how
I starting falling apart.

I am sorry for my slow learning but this is my first time with any
programming effort, I could tell you only after reaching dead end of
the efforts I am knocking.

Thanks
Prakash

On Mon, Apr 16, 2012 at 4:25 AM, Friedrich Huebler <fhuebler@gmail.com> wrote:
> 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/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index