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: extracting of data


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: extracting of data
Date   Mon, 31 Dec 2012 13:29:47 +0000

Your code contains at least one bug. You try to create a temporary
variable `f1' but the only previous declaration of a temporary
variable uses the name "fsu1".

However, the code

tempvar fsu1
gen str5 (`f1')=string(f_no)
tempvar segment1
gen str1 (`segment1')=string(segment)
tempvar sss1
gen str1 (`sss1')=string(sss)
tempvar ent_no1
gen str2 (`ent_no1')=string(ent_no)
gen str9 common_id= `f1' + `segment1' + `sss1' + `ent_no1'

can probably all be replaced by

egen common_id = concat(f_no segment sss ent_no)

Nick

On Mon, Dec 31, 2012 at 12:13 PM, Prakash Singh <[email protected]> wrote:

> I have a survey data in such a way that the data is divided into 9 levels
> for each level I need to prepare 9 dictionary files.
> I managed to write programme for this but still I need to repeat this
> for level (1 to 9) equivalent number of times.
> Is there any way that I can reduce the repetition work.
>
> here is my code
>
> clear
> set more off
> set mem 500m
> tempfile mydata
> foreach level of numlist 11/19 {
>    infile using D:\TEAM_PC\level`level'.dct, clear
>    capture append using `mydata'
>     save `mydata', replace
> }
> use `mydata', clear
> tempvar fsu1
> gen str5 (`f1')=string(f_no)
> tempvar segment1
> gen str1 (`segment1')=string(segment)
> tempvar sss1
> gen str1 (`sss1')=string(sss)
> tempvar ent_no1
> gen str2 (`ent_no1')=string(ent_no)
> gen str9 common_id= `f1' + `segment1' + `sss1' + `ent_no1'
> keep if level==1
> save level1_list.dta", replace
>
> clear
> set more off
> set mem 500m
> tempfile mydata
> foreach level of numlist 21/29 {
>    infile using D:\TEAM_PC\level`level'.dct, clear
>    capture append using `mydata'
>     save `mydata', replace
> }
> use `mydata', clear
> tempvar fsu1
> gen str5 (`f1')=string(f_no)
> tempvar segment1
> gen str1 (`segment1')=string(segment)
> tempvar sss1
> gen str1 (`sss1')=string(sss)
> tempvar ent_no1
> gen str2 (`ent_no1')=string(ent_no)
> gen str9 common_id= `f1' + `segment1' + `sss1' + `ent_no1'
> keep if level==2
> save level1_list.dta", replace
>
> till level==9
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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