Announcement

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

  • code efficiency combining graphs without having to clear all

    I've plotted two graphs . However I have to run a long do file of code.

    I would like to plot 2 graphs

    First one: with -failure reason- over -gender- FOR failures within 2 years
    Then plot another graph with -failure reason- over -gender- FOR failures AFTER 2 years

    However, as the -graph- does not support -if years2== 1- I keep having to run my long do file
    then

    drop if years2== 0 run the following code

    Code:
    graph bar (percent), over(failurereason) over(gender) asyvars
    Then ...

    Code:
    clear all 
    /// Run the code again
    
    drop if years2 == 1 
    graph bar (percent), over(failurereason) over(gender) asyvars
    If you could suggest a code where I could keep the dataset and run the above codes without having to -clear all- I could then keep by 2 graphs (years2=0 ; year2=1) on the same graph page by using

    Code:
    graph combine m1 m2

    thanks




  • #2
    There's no need to clear your dataset between graphing commands. Also, -graph- (like pretty much all other Stata commands) support if/in qualifiers. Something like the below should work (though note it is untested).

    [quote]
    graph bar (percent), over(failurereason) over(gender) asyvars name(m1, replace)
    graph bar (percent) if years2==0, over(failurereason) over(gender) asyvars name(m2, replace)
    graph combine m1 m2
    [/code]

    Comment

    Working...
    X