Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Differnt ytitle for each loop?

    How do i change the ytitle so it changes in every loop?

    Thank you in advance!

    This code gives me the variable names - I want to show the real names instead.
    *HGB, Phoshourus, Calcium and vitamin D.
    foreach x in "HGB" "fosfor" "ca" "D3_vit"{
    regress `x' Total_CO2 AGE DATUM i.SEASON
    twoway (lfit `x' Total_CO2, lcolor(black) lwidth(medthick)) || (lfit `x' Total_CO2 if SEX==0, lcolor(red) lpattern(dash)) || (lfit `x' Total_CO2 if SEX==1, lcolor(blue) lpattern(dash)), legend(label (1 "All") label (2 "Women") label (3 "Men")) xtitle("Dietary GHGE (kg/day)") ytitle(`x')


    And this one is not correct.
    foreach x in "HGB" "fosfor" "ca" "D3_vit"{
    regress `x' Total_CO2 AGE DATUM i.SEASON
    twoway (lfit `x' Total_CO2, lcolor(black) lwidth(medthick)) || (lfit `x' Total_CO2 if SEX==0, lcolor(red) lpattern(dash)) || (lfit `x' Total_CO2 if SEX==1, lcolor(blue) lpattern(dash)), legend(label (1 "All") label (2 "Women") label (3 "Men")) xtitle("Dietary GHGE (kg/day)") ytitle(order(1 "Hemoglobin" 2 Phoshourus 3 Calcium 4 Vitamin D))

  • #2
    Spelling is phosphorus in English. I have here corrected that and made various other simplifications and corrections. But I can't test the code.

    Note that legend(order()) is nothing to do with order within a loop.

    The best way is just to define variable labels in advance.

    Shouldn't SEX (better called Male) be included in the regression?


    Code:
    label var HGB "Hemoglobin"
    label var fosfor "Phosphorus"
    label var ca "Calcium"
    label var D3_vit "Vitamin D"
    
    foreach y in HGB fosfor ca D3_vit {
         regress `y' Total_CO2 AGE DATUM i.SEASON
        
         twoway lfit `y' Total_CO2, lcolor(black) lwidth(medthick) ///
         || lfit `y' Total_CO2 if SEX==0, lcolor(red) lpattern(dash) ///
         || lfit `y' Total_CO2 if SEX==1, lcolor(blue) lpattern(dash) ///
         legend(order(1 "All" 2 "Women" 3 "Men")) xtitle("Dietary GHGE (kg/day)") ///
         ytitle("`: var label `y''")
    }
    Last edited by Nick Cox; 17 Aug 2023, 03:31.

    Comment


    • #3
      Thank you so much! And thank you for pointing out the spelling mistakes.

      Comment

      Working...
      X