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]

st: extracting of data


From   Prakash Singh <[email protected]>
To   statalist <[email protected]>
Subject   st: extracting of data
Date   Mon, 31 Dec 2012 17:43:55 +0530

Dear all
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



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