Announcement

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

  • Labmask command with parallel trends

    Hello Members,

    Below is a code taken from this post: https://www.statalist.org/forums/for...nel-data-graph

    Is there a way to modify this code to include parallel trends?

    I would appreciate any help!

    Thanks,
    Anoush

    Code:
     // open some example data
    clear all
    use "https://www.rug.nl/ggdc/docs/pwt90.dta", clear
    gen gdppc = rgdpe/ pop
    eep country year gdppc pl_con  
    
    // keep the first 35 countries
    bys country (year) : gen mark =  _n == 1
    replace mark = sum(mark)
    keep if mark <= 35 drop mark  
    // sort countries by their average price level
    bys country : egen mean = mean(pl_con)
    egen order = rank(mean), track
    labmask order, values(country)  
    // add background lines
    tempfile temp
    save `temp'  
    
    separate pl_con, by(country) veryshortlabel
    
    forvalues i = 1/35 {    
    bys year (pl_con`i') : replace pl_con`i' = pl_con`i'[1]    
    by year : gen gdppc`i' = gdppc[1]
    }
    
    keep if country == "Albania"
    keep year pl_con? pl_con?? gdppc? gdppc??
    merge 1:m year using `temp'  
    
    local gr ""
    forvalues i = 1/35 {    
    local gr `gr' line pl_con`i' gdppc`i', lpattern(solid) lcolor(gs12) ||
    }  
    
    // final graph
    sort order year
    twoway `gr' ///    
    line pl_con gdppc , by(order, legend(off) compact note("")) ///    
    lpattern(solid) lwidth(*1.2) ///    
    xscale(log) xlab(1000 "10{sup:3}" 10000 "10{sup:4}" 100000 "10{sup:5}") ///    
    xtitle("GDP per capita (log scale)") ytitle("price level (USA 2011 = 1)")
    Last edited by Anoush Khachatryan; 13 Apr 2022, 10:43.

  • #2
    Thanks so much for including a way to get your real data- I think people should do this more often if the can. Anyways, I've corrected a few errors in your code
    Code:
    // open some example data
    clear all
    use "https://www.rug.nl/ggdc/docs/pwt90.dta", clear
    gen gdppc = rgdpe/ pop
    keep country year gdppc pl_con  
    
    // keep the first 35 countries
    bys country (year) : gen mark =  _n == 1
    replace mark = sum(mark)
    keep if mark <= 35
    
    drop mark  
    // sort countries by their average price level
    bys country : egen mean = mean(pl_con)
    egen order = rank(mean), track
    labmask order, values(country)  
    // add background lines
    tempfile temp
    save `temp'  
    
    separate pl_con, by(country) veryshortlabel
    
    forvalues i = 1/35 {    
    bys year (pl_con`i') : replace pl_con`i' = pl_con`i'[1]    
    by year : gen gdppc`i' = gdppc[1]
    }
    
    keep if country == "Albania"
    keep year pl_con? pl_con?? gdppc? gdppc??
    merge 1:m year using `temp'  
    
    local gr ""
    forvalues i = 1/35 {    
    local gr `gr' line pl_con`i' gdppc`i', lpattern(solid) lcolor(gs12) ||
    }  
    
    // final graph
    sort order year
    twoway `gr' ///    
    line pl_con gdppc , by(order, legend(off) compact note("")) ///    
    lpattern(solid) lwidth(*1.2) ///    
    xscale(log) xlab(1000 "10{sup:3}" 10000 "10{sup:4}" 100000 "10{sup:5}") ///    
    xtitle("GDP per capita (log scale)") ytitle("price level (USA 2011 = 1)")
    My only question is what do you mean by
    modify this code to include parallel trends
    and are you sure this, uhh, massive graph is the best medium to convey whatever you mean to convey?

    Comment


    • #3
      I am the author of labmask (which can be found on SSC, but I ask that people mention Stata Journal as the source).

      I can't see that its use has anything in particular to do with parallel trends.

      Comment


      • #4
        Thank you Jared Greathouse and Nick Cox for your responses.

        Using the graphs produced from the above code (shown here: https://www.statalist.org/forums/for...nel-data-graph), I would like to include a second line, per graph, for a comparison group. I am interested in the general trends of the treatment and comparison groups. If labmask isn't the best way to go about this, is there something else you would recommend?

        Thanks,
        Anoush

        Comment


        • #5
          I didn't say that labmask wasn't useful. My point was rather that I didn't see that you need anything different from it just because you are interested in parallel trends.

          Comment


          • #6
            I share Nick's confusion about the relevance of labmask here. I only ever use it when I want to label an already existing variable if I can't use egen to do so.

            When I think of a comparison group, I think of plotting the average of a control group against the observed outcomes of a treated unit, or I think of a counterfactual that I've created by weighting or some other means. Are you doing a difference-in-differences analysis? What exactly are we working with here?

            The trouble here is that I don't know what parallel trends has to do with the labmask command. There's not even a treatment variable/indicator here, so I'm a little confused on how labmask is relevant at all for this problem. Are you really just asking how to plot the values of one country versus the averages of another set of countries?

            Comment


            • #7
              I apologize for the confusion.

              Are you really just asking how to plot the values of one country versus the averages of another set of countries?
              Yes! That is exactly what I am asking. I am not sure how to plot this.

              Comment

              Working...
              X