Seite 1 von 1

Daten umformatieren

BeitragVerfasst: Mi 9. Mai 2012, 11:46
von Apollo
Hallo zusammen,
ich soll Daten-Dateien umformatieren. Ich habe dazu ein .do-file, das mein Prof schon gecheckt hat und sagt, bei ihm funktioniert es. Bei mir passiert einfach nichts - das do-file läuft geräusclos ab, aber offensichtlich ohne in die Schleife einzusteigen (da sollte sonst eine Anzeige kommen). Ich bin mir sicher, dass der Fehler winzig ist - z.B. ein verdrehtes / oder so, aber ich finds einfach nicht.

Ich wäre euch dankbar, wenn ihr mir helfen könntet!

clear
set mem 500m
set more off
set trace off


cd "C:/Users/Kira/Uni/10.Semester/Projektmodul/"
global datadir = "C:/Users/Kira/Uni/10.Semester/Projektmodul/"
global datadir1 = "C:/Users/Kira/Uni/10.Semester/Projektmodul/Data/"
global datadir2 = "C:/Users/Kira/Uni/10.Semester/Projektmodul/Data/Right Format/"


local syear
local smonth

/*********************************************
Jan 2003- Mar 2004
Dictionary file is own, so no adjustments
for merging necessary
*********************************************/
local dctstring = "${datadir}cpsbjan03.dct"
foreach syear in 03 {
foreach smonth in 01 02 03 04 05 06 07 08 09 10 11 12{
local fstring = "${datadir1}cpsb`syear'`smonth'."
local dstring = "${datadir2}cpsb`syear'`smonth'.dta"
display "=============================="
display " Reading in `syear'/`smonth'"
display "=============================="
quietly : infile using `dctstring', using(`fstring') clear


/* Generate unique identifier */
gen hhid1 = hrhhid + hrhhid2
destring hhid1, generate(hhid) force
drop if hhid >= .

rename pulineno lineno
rename ptdtrace race
rename pesex sex
rename peage age
rename hrmis mis
rename pemaritl maritalstat
rename gestcen state
rename peeduca educ
recode educ (31 = 0) (32 = 4) (33 = 6) (34 = 8) (35 = 9) (36 = 10) (37 = 11) (38 = 11) (39 = 12) (40/42 = 15) (43/46 = 16)
label variable educ "Completed education recoded in years of education"

/* Adjustment for flow analysis */
rename pemlr status
rename puiodp1 prevempl
rename prunedur utenure
rename peio1icd industry
rename peio1ocd occupation
rename peio1cow workerclass
rename pehractt hours
rename pehruslt fulltime
rename pwsswgt wgt

/* Keep only variables necessary for merging and flow analysis*/
keep hhid lineno race sex age maritalstat mis state educ status utenure workerclass hours fulltime industry occupation prevempl wgt

/* Code -1 as missing value */
mvdecode _all, mv(-1)


save "`dstring'", replace
}
}

Re: Daten umformatieren

BeitragVerfasst: Mi 9. Mai 2012, 23:55
von daniel
Ich habe jetzt nicht das ganze do-file gelesen, aber der loop beginnt ja bereits innerhalb der ersten paar Zeilen und Du sagst, die -display- commands werden schon nicht ausgeführt.

Mein Vorschlag: ändere mal

. set more off
. set trace off

in

. set more on
. set trace on

und schau Dir mal an, an welcher Stelle es hakt.

Btw. Der erste loop is überflüssig, da <syear> nur eine Wert (03) annimmt.