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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: extracting of data


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
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 <prakashbhu@gmail.com> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index