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 22:34:36 +0530

Nick, I am able to run the code till - save "level`l'data.dta",replace
- successfully but for remaining for remaining part of the code it
either says invalid syntax or data not found.

Please have look on code lines after - save "level`l'data.dta",replace.


Prakash


On Mon, Apr 16, 2012 at 8:12 PM, Nick Cox <[email protected]> wrote:
> Posting a chunk of code and giving no details of precisely what errors
> you are getting is not strongly recommended. But a wild guess is this:
>
> Your branches like
>
> if level==3 | level==5 {
> }
> if level==4| level ==6| level==7 {
> }
> if level==8 {
> }
> if level==9 {
>  }
>
> make reference to -level- but what do you think it is? From the outer
> loop I suspect that
>
> level
>
> should in each case be
>
> `l'
>
> Nick
>
> On Mon, Apr 16, 2012 at 1:23 PM, Prakash Singh <[email protected]> wrote:
>> 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
>>
>
> *
> *   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