Übersichten/Hilfen

Liebe FDZlerInnen,
gibt es vll. irgendwo eine Tabelle/Übersicht, der man unmittelbar entnehmen kann, welche Variablen in welchen Wellen erhoben wurden und in welchen nicht (z.B. für die SC3)? Z.B. soetwas:

                Welle 1    Welle 2    Welle 3    ....
 Variable_1       X          NA             X 
 Variable_2       X           X             X
 Variable_3       X          NA             X
 ....

Wäre super hilfreich!

LG
Nicolas

Hallo Nicolas!

Ich habe hier ein kleines do-file, damit kann man für jeden SUF passende Excel-Sheets ganz fix erzeugen. Du musst einfach nur die locals anpassen und schon kann es losgehen.

Viele Grüße
Dietmar

version 12

// define locals 
quietly {
noisily: display as text "specify locals before your start!!!"
local cohort SC3
local version 11-0-1
local sufpath <PATH_TO_DATA> // e.g. C:/Users/JaneDoe/Desktop/Data/SC3_11-0-1/Stata14
local level D
local targetfile <PATH_TO_EXCELSHEET>/<NAME_OF_EXCELSHEET> // e.g. `"C:/Users/JaneDoe/Desktop/NEPS_Stuff/SC3_varnames_X_wave.xlsx"'

noisily: display as text "install {bf:nepsmgmt} to use this syntax!!!"
net install nepsmgmt, from(http://nocrypt.neps-data.de/stata)

noisily: display as text "find files to create varnames x wave - list"
filesearch .*\.dta, dir("`sufpath'") regex local(suffiles) 
foreach suffile of local suffiles {
	if regexm("`suffile'","^`cohort'_(.*)_`level'_`version'\.dta$")  local shortname = regexs(1)
	if !regexm("`shortname'","^sp") {  // skip episode files, because wave doesn't make sense

		capture: describe wave using "`sufpath'/`suffile'"  // check if wave is there
		if _rc == 0 {
			local appendlist ""
			noisily: display as text "{bf: processing `shortname'}... found variable {it:wave} opening dataset!!!"
			use "`sufpath'/`suffile'" , clear 
			
			preserve
			noisily: display as text "{tab}>> create table of variable names and positions to sort lines later"
			describe, replace 
			keep position name
			tempfile poslist
			save "`poslist'", replace
			restore
			
			noisily: display as text "{tab}>> slicing data into separate waves..."

			sum wave
			forvalues wave=-29/`r(max)' {
				preserve
				keep if wave == `wave'
				count
				local old_obs `r(N)'
				
				if `old_obs' > 0 {
					noisily: display as text "{tab}{bf:processing wave `wave'}... keeping wave-`wave'-data"
						
					noisily: display as text "{tab}{tab}drop all variables only filled with design missings"

					foreach var of varlist _all {
						if regexm("`: type `var''","str") count if regexm(`var',"^-54")
						else count if `var' == -54
						if `r(N)'==`old_obs' drop `var'
					}
					
					describe, replace clear
					keep name varlab
					if `wave' > 0 generate wave_`wave' = 1
					else{
						local wave=(`wave')*(-1)
						generate wave_min`wave' = 1
					}
					noisily: display as text "{tab}{tab}save list of filled variables"

					tempfile varlist_wave`wave'
					save "`varlist_wave`wave''", replace
					local appendlist :  list appendlist | varlist_wave`wave'
				}
				restore
			}
			
			local maxappend =  `: word count `appendlist''
	
			noisily: display as text "{tab}{bf:merging wave-specific file lists} to create varnames-X-wave-matrix" 
			if `: word count `appendlist'' >= 1 {
				clear
				local cntr 0
				
				foreach file of local appendlist {
				
					local `++cntr'
					if `cntr' == 1 use "`file'", clear
					else merge 1:1 name using "`file'", nogenerate noreport nolabel
					
					foreach var of varlist wave_* {
						replace `var' = 0 if missing(`var')
					}
					
					if `cntr' == `maxappend' {
						merge 1:1 name using "`poslist'", nogenerate noreport nolabel
						sort position
						drop position
						export excel using `"`targetfile'"', firstrow(variables) sheet("`shortname'")
					}
				}
				noisily: display as text "{tab}{tab}{bf:export list} to {it:`targetfile'} - sheet: `shortname'"
			}
			noisily: display as text "{dup 60:+}
		}
	}
}
noisily: display as text "{bf:...done!!!}"
}
clear
exit 0 
end
// EOF
2 Likes

Merci Dietmar,
probiere ich aus und melde mich nochmal, falls etwas nicht klappt.
LG
Nicolas