Announcement

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

  • bar graph diff-in-diff between subjects

    Dear Statalists,

    Given the following dataset

    Code:
    ID    var1    treatment    subtreatment
    1    3    1    1
    2    5    1    1
    3    4    1    2
    4    6    1    2
    5    3    2    1
    6    5    2    1
    7    6    2    2
    8    4    2    2
    9    1    2    2
    I would like to create a bar graph that compares the treatment effect as the difference in var1 between subtreatments. I know the following command doesn't conform with the row-wise data structure in Stata, but I would like to have something like:

    Code:
    cibar (mean(var1) if treatment==1) - (mean(var1) if treatment==2), over(subtreatment
    I'm grateful for any ideas,
    Frieder

  • #2
    Where does that command come from (FAQ Advice #12) and what does the result look like?

    stripplot from SSC can show the data and means and confidence intervals too.

    Code:
    clear 
    input ID    var1    treatment    subtreatment
    1    3    1    1
    2    5    1    1
    3    4    1    2
    4    6    1    2
    5    3    2    1
    6    5    2    1
    7    6    2    2
    8    4    2    2
    9    1    2    2
    end 
    
    set scheme s1color 
    stripplot var1, over(subtreatment) by(treatment, note("")) bar cumul cumprob vertical height(0.2) xline(1.5, lw(thin) lc(gs8)) yla(, ang(h)) subtitle(Treatment)
    Click image for larger version

Name:	notcibar.png
Views:	1
Size:	21.1 KB
ID:	1662866


    If the real dataset is much larger, height(0.2) should be deleted.

    Comment


    • #3
      I appreciate the suggestion, Nick. But it is not exactly what I'm looking for.

      cibar is from SSC. I'm using it because it comes with confidence intervals and suitable coloring.

      My question was based on the following command:

      Code:
      cibar var1, over(treatment subtreatment)
      which creates this graph

      Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	34.4 KB
ID:	1662918


      What I'm after is this graph structure with just one bar for each subtreatment that represents the corresponding difference between treatment 1 and treatment 2. Ideally, I would also get the confidence intervals for the computed difference in means.



      Comment


      • #4
        That's the much detested detonator plot or dynamite plot or plunger plot.

        See commentary at e.g.

        http://emdbolker.wikidot.com/blog:dynamite

        https://simplystatistics.org/posts/2...lots-must-die/

        You want something different -- and certainly stripplot doesn't support it and I don't know what does.

        I fear that you need to write your own code.

        Comment


        • #5
          If I understand this correctly, your differences should come out of an appropriate model fit, so the question hinges on what that would be. It could be a plain ANOVA or something else, depending on your design. I think you'll get better advice on that from other people but you'd need to give more information first.

          Comment


          • #6
            Thank you for making me aware of the general dislike for these types of graphs. I will gladly adjust. Essentially, I would like to show the difference between the mean or median statistic of treatment 1 and treatment 2 using one bar/strip for each of the two subtreatments. I want to reduce the effort for the human eye to extracting the treatment effect across subtreatments by comparing two bars/strips to each other.

            In other words, I would like to visualize the "difference-in-difference" effect of two between-subject variables from the following regression model:

            Code:
            reg var1 i.treatment##i.subtreatment

            Comment


            • #7
              OK, but medians are not estimated by that model. Again, this is territory more frequently traversed by other people here.

              Comment

              Working...
              X