graphen erstellen mit forloop

Fragen zu Stata Syntax und Do-Files.

graphen erstellen mit forloop

Beitragvon roblocks » Sa 20. Feb 2016, 18:19

Hey zusammen,
folgendes Minimal beispiel zeigt mein problem:

Code: Alles auswählen
webuse grunfeld, clear
keep if company <5
g ret=invest/15000
bys company (year): g cumul=ret if _n==1
replace cumul=ret+l.cumul if mi(cumul)

// Create names
gen name = "company1" if company == 1
replace name = "company2" if company == 2
replace name = "company3" if company == 3
replace name = "company4" if company == 4


forvalue i=1(1)4 {
   
    twoway line cumul year if company == `i'
    graph export company`i'.png, replace
}


ich würde jetzt gerne haben, dass man (1) den firmennamen "name" mit in die grafik aufnehmen kann und (2) die datei unter diesem Namen speichern kann.

Leider sind die Namen teilweise sehr speziell, zb "wort wort wort: zahl.wort ", hatte zunächst das hier probiert:

Code: Alles auswählen
webuse grunfeld, clear
keep if company <5
g ret=invest/15000
bys company (year): g cumul=ret if _n==1
replace cumul=ret+l.cumul if mi(cumul)

// Create names
gen name = "company1" if company == 1
replace name = "company2" if company == 2
replace name = "company3" if company == 3
replace name = "company4" if company == 4

local companies="company1 company2 company3 company4"

foreach i of local companies {
    local j="Cumulative returns `i'"
    twoway line cumul year if name == "`i'", title("`j'")
    graph export `i'.png, replace
}


aber local companies is schwer zu erstellen, da die alle sehr komisch heißen, deshalb fürchte ich, ich muss auf die erste alternative zurückgreifen und einen weg finden, auf "name" by id zuzugreifen. Irgendjemand eine Idee wie das geht?

Danke im vor raus!

Grüße!

roblocks
roblocks
 
Beiträge: 1
Registriert: So 27. Dez 2015, 14:56
Danke gegeben: 0
Danke bekommen: 0 mal in 0 Post

Zurück zu Stata Syntax

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 3 Gäste

cron