Announcement

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

  • Adding a variable to the variable's axis of a coefficients plot made with "coefplot"

    Hello everybody.

    Does anyone know how I can add the name of the variable corresponding to the omitted interaction (the interaction between a dummy variable and the reference category of a categorical variable) to the variable's axis of a coefficients plot made with command "coefplot"? In variable axis of the graph, I´m showing 5 variables (-3, -2, -1, 1 and 2). Each variable corresponds to the interaction between a dummy variable and a category (period) of a time variable. Because period 0 is the reference category, interaction between the dummy and period 0 is omitted. However, I need period 0 to be shown in the variable axis of the graph. Because there is no coefficient to period 0, “coefplot” don’t show me the variable. However, I need it.

    Code:
    coefplot (Homicidio_total), ///
    yline (0) ///
    vertical ///
    keep (1.tratamiento#1.mes2 1.tratamiento#2.mes2 1.tratamiento#3.mes2 1.tratamiento#4.mes2 1.tratamiento#5.mes2) ///
    coeflabels (1.tratamiento#1.mes2 = "-3" 1.tratamiento#2.mes2 = "-2" 1.tratamiento#3.mes2 = "-1" 1.tratamiento#4.mes2 = "1" 1.tratamiento#5.mes2 = "2") ///
    xtitle(Months) ///
    msymbol(o) ///
    levels(99 95)
    I need the graph that has a 0 in the x axis, but I currently have the grpah that doesn't have a 0 in the x axis (I need a 0 between -1 and 1).


    Attached Files

  • #2
    coefplot is from SSC, authored by Ben Jann. You are asked to specify the source of user-written commands, see the FAQs. You have the baselevels option in coefplot to include the base level in the plot

    Code:
    coefplot, baselevels
    You also have the addplot option to include additional plots as well as the possibility of extracting the regression results from r(table) and putting these into a matrix, then plotting as shown in #4 of this link. Having said all that, the base coefficient has a value of zero and no confidence interval. Including it in the plot serves no useful purpose and you could just add a note at the bottom of the graph stating "the base category is month=0".

    Comment


    • #3
      Thank you very much Andrew. I was able to do what I wanted thanks to your advise. Now, I'm just wondering how to eliminate the dot corresponding to month 0. Is there a way to eliminate this dot only, or at least, a way to reduce its size? I tried the following 2 options but they didn't work:

      Code:
      msize (small small small tiny small small)
      
      msize (2.3 2.3 2.3 1 2.3 2.3)
      The full code of my graph is the following:

      Code:
      reg Homicidio_total i.tratamiento##i.mes2 i.hora i.fecha, vce(cluster fecha)
      
      coefplot, ///
      baselevel ///
      drop (*tratamiento 0.tratamiento#0.mes2 1.mes2 2.mes2 3.mes2 4.mes2 5.mes2 _cons *hora_entera *fecha) ///
      order (1.tratamiento#1.mes2 1.tratamiento#2.mes2 1.tratamiento#3.mes2) ///
      coeflabels (0.mes2 = "0" 1.tratamiento#1.mes2 = "-3" 1.tratamiento#2.mes2 = "-2" 1.tratamiento#3.mes2 = "-1" 1.tratamiento#4.mes2 = "1" 1.tratamiento#5.mes2 = "2") ///
      xtitle(Mes, size (vsmall)) ///
      vertical ///
      xline (4, lpattern(dash)) ///
      yline (0) ///
      msymbol(o) ///
      levels(99 95 90) ///
      ciopts(lwidth(*1 *2 *3)) ///
      legend(title ("Niveles de confianza", size (vsmall)) order(1 "99%" 2 "95%" 3 "90%") row (1) size (vsmall)) ///
      ylabel(,labsize(vsmall)) ///
      xlabel(,labsize(vsmall)) ///
      msize (2.3) ///
      legend(symys(*.5) symxs(*.5) size(3) region(c(none)) bm(tiny))
      This is the graph:
      Attached Files

      Comment


      • #4
        You do not provide a data example, but here is one way. The idea is to turn the coefficient of the base category from zero to missing. You will not be able to do this directly in the stored coefficients' matrix -e(b)-, but as stated in #2, coefplot allows you to use a matrix as the input.

        Code:
        sysuse auto
        regress mpg i.rep78
        *PUT REGRESSION RESULTS IN A MATRIX
        mat r= r(table)
        *WE JUST NEED THE FIRST 6 ROWS IN THIS INSTANCE.
         mat R= r[1..6,1..6]
        *SAME PLOT AS RUNNING COEFPLOT AFTER REGRESSION
        coefplot matrix(R), drop(_cons) se(2) baselevels
        *BASE LEVEL 1b.rep78. TURN COEFFICIENT FROM 0 TO MISSING
        mat list R
         mat R[1,1]=.
        *PROCEED
        coefplot matrix(R), drop(_cons) se(2) baselevels

        Click image for larger version

Name:	Graph.png
Views:	1
Size:	27.9 KB
ID:	1469748
        Last edited by Andrew Musau; 10 Nov 2018, 06:41.

        Comment


        • #5
          Hi Andrew, thank you very much again. I was finally able to make the graph I wanted. I just had to add coefplot option "omitted" to your code.
          Code:
          *Regression
          reg yvar i.tratamiento##i.mes2 i.hora i.fecha, vce(cluster fecha)
          
          *Matrix
          mat resultados = r(table)
          mat grafico = resultados[1..6, 15..20]
          mat grafico[1,1]=.        
              
          *Graph
          coefplot matrix(grafico), ///
          se(2) ///
          baselevels ///
          omitted ///
          order (1.tratamiento#1.mes2 1.tratamiento#2.mes2 1.tratamiento#3.mes2) ///
          coeflabels (1.tratamiento#0.mes2 = "0" 1.tratamiento#1.mes2 = "-3" 1.tratamiento#2.mes2 = "-2" 1.tratamiento#3.mes2 = "-1" 1.tratamiento#4.mes2 = "1" 1.tratamiento#5.mes2 = "2") ///
          xtitle(Meses, size (vsmall)) ///
          vertical ///
          xline (4, lpattern(dash) lcolor(black)) ///
          yline (0, lwidth (medthin)) ///
          msymbol(o) ///
          levels(99 95 90) ///
          ciopts(lwidth(*1 *2 *3)) ///
          legend(title ("Niveles de confianza", size (vsmall)) order(1 "99%" 2 "95%" 3 "90%") row (1) size (vsmall)) ///
          ylabel(,labsize(vsmall)) ///
          xlabel(,labsize(vsmall)) ///
          msize (2.3) ///
          legend(symys(*.5) symxs(*.5) size(3) region(c(none)) bm(tiny))
          Attached Files

          Comment


          • #6
            Hi All,

            I was not sure if I should post on my other question here but my current question relates more to this thread than the other. I want to be able to insert a "2016" entry since it is omitted in my regression and use it as a dotted line as seen above. I currently have it entirely omitted, so I tried to use "baseleves" and "omitted" as options in "coefplot," but it unfortunately does not change how the graph itself appears. Do you have any idea why this may be? Thank you so much for any and all advice!

            Best,
            Jim

            Code:
               reg percent i.id_test5 ib2016.year i.year##soft_drink if country=="UK" & type==1, robust  //regression I run to see how percent breakdown of sugar changes over time. I want to see 
                //just doing 1 year lead/lag does not work becasue the former year is colinear with the following year
                
                 matrix A = e(b)
            local namecol "`: colnames A'"
            
            tokenize `namecol'
            
            forvalues i = 1 / `=colsof(matrix(A))' {
                local mv = A[1,`i']
                if `mv' != 0 & strmatch("``i''" , "*#*") {
                    local coefinter `coefinter' ``i''
                }
            }
            
            coefplot, keep(`coefinter') vertical title("Ireland Ingredient Soft Drink * Time Interaction Coefficients") xtitle(Years relative to 2016) baselevels omitted yline(0, lpattern("-##")) mlabel(cond(@pval<.05, "***", cond(@pval<.1, "**", cond(@pval<.05, "", ""))))


            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input str14 country str43 prod int year byte type float percent long id_test5 float(new_id soft_drink) str11 newprod long product
            "Ireland" "Baby Food"         2014 0    88.76344 2  1 0 "Others"      1
            "Ireland" "Baby Food"         2015 0    88.85345 2  1 0 "Others"      1
            "Ireland" "Baby Food"         2016 0    88.91432 2  1 0 "Others"      1
            "Ireland" "Baby Food"         2017 0    88.97702 2  1 0 "Others"      1
            "Ireland" "Baby Food"         2018 0    89.05828 2  1 0 "Others"      1
            "Ireland" "Baby Food"         2019 0    89.15837 2  1 0 "Others"      1
            "Ireland" "Baby Food"         2020 0    89.23181 2  1 0 "Others"      1
            "Ireland" "Baby Food"         2014 1    11.23656 2  2 0 "Others"      1
            "Ireland" "Baby Food"         2015 1   11.146546 2  2 0 "Others"      1
            "Ireland" "Baby Food"         2016 1   11.085676 2  2 0 "Others"      1
            "Ireland" "Baby Food"         2017 1   11.022975 2  2 0 "Others"      1
            "Ireland" "Baby Food"         2018 1   10.941716 2  2 0 "Others"      1
            "Ireland" "Baby Food"         2019 1    10.84163 2  2 0 "Others"      1
            "Ireland" "Baby Food"         2020 1   10.768182 2  2 0 "Others"      1
            "Ireland" "Baked Goods"       2014 0    96.40752 3  3 0 "Others"      1
            "Ireland" "Baked Goods"       2015 0    96.42551 3  3 0 "Others"      1
            "Ireland" "Baked Goods"       2016 0    96.42312 3  3 0 "Others"      1
            "Ireland" "Baked Goods"       2017 0    96.40865 3  3 0 "Others"      1
            "Ireland" "Baked Goods"       2018 0     96.3924 3  3 0 "Others"      1
            "Ireland" "Baked Goods"       2019 0    96.44029 3  3 0 "Others"      1
            "Ireland" "Baked Goods"       2020 0    96.34309 3  3 0 "Others"      1
            "Ireland" "Baked Goods"       2014 1     3.59136 3  4 0 "Others"      1
            "Ireland" "Baked Goods"       2015 1   3.5733924 3  4 0 "Others"      1
            "Ireland" "Baked Goods"       2016 1    3.575801 3  4 0 "Others"      1
            "Ireland" "Baked Goods"       2017 1    3.590291 3  4 0 "Others"      1
            "Ireland" "Baked Goods"       2018 1   3.6065545 3  4 0 "Others"      1
            "Ireland" "Baked Goods"       2019 1    3.558706 3  4 0 "Others"      1
            "Ireland" "Baked Goods"       2020 1    3.655866 3  4 0 "Others"      1
            "Ireland" "Baked Goods"       2014 2 .0011187661 3  5 0 "Others"      1
            "Ireland" "Baked Goods"       2015 2 .0011032855 3  5 0 "Others"      1
            "Ireland" "Baked Goods"       2016 2 .0010741096 3  5 0 "Others"      1
            "Ireland" "Baked Goods"       2017 2 .0010554073 3  5 0 "Others"      1
            "Ireland" "Baked Goods"       2018 2 .0010359032 3  5 0 "Others"      1
            "Ireland" "Baked Goods"       2019 2 .0010000111 3  5 0 "Others"      1
            "Ireland" "Baked Goods"       2020 2 .0010402437 3  5 0 "Others"      1
            "Ireland" "Bottled Water"     2014 0    99.74924 4  6 0 "Others"      1
            "Ireland" "Bottled Water"     2015 0    99.75259 4  6 0 "Others"      1
            "Ireland" "Bottled Water"     2016 0     99.7564 4  6 0 "Others"      1
            "Ireland" "Bottled Water"     2017 0    99.76518 4  6 0 "Others"      1
            "Ireland" "Bottled Water"     2018 0    99.76906 4  6 0 "Others"      1
            "Ireland" "Bottled Water"     2019 0     99.7739 4  6 0 "Others"      1
            "Ireland" "Bottled Water"     2020 0    99.78398 4  6 0 "Others"      1
            "Ireland" "Bottled Water"     2014 1   .24856895 4  7 0 "Others"      1
            "Ireland" "Bottled Water"     2015 1       .2453 4  7 0 "Others"      1
            "Ireland" "Bottled Water"     2016 1    .2415012 4  7 0 "Others"      1
            "Ireland" "Bottled Water"     2017 1   .23278593 4  7 0 "Others"      1
            "Ireland" "Bottled Water"     2018 1    .2289391 4  7 0 "Others"      1
            "Ireland" "Bottled Water"     2019 1    .2241746 4  7 0 "Others"      1
            "Ireland" "Bottled Water"     2020 1    .2141973 4  7 0 "Others"      1
            "Ireland" "Bottled Water"     2014 2 .0021854744 4  8 0 "Others"      1
            "Ireland" "Bottled Water"     2015 2    .0021185 4  8 0 "Others"      1
            "Ireland" "Bottled Water"     2016 2 .0020976719 4  8 0 "Others"      1
            "Ireland" "Bottled Water"     2017 2 .0020299621 4  8 0 "Others"      1
            "Ireland" "Bottled Water"     2018 2 .0019979784 4  8 0 "Others"      1
            "Ireland" "Bottled Water"     2019 2 .0019317467 4  8 0 "Others"      1
            "Ireland" "Bottled Water"     2020 2 .0018214793 4  8 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2014 0    88.36055 5  9 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2015 0    88.84888 5  9 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2016 0    89.38763 5  9 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2017 0    89.83304 5  9 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2018 0    89.93861 5  9 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2019 0    90.04226 5  9 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2020 0    90.45103 5  9 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2014 1   11.639448 5 10 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2015 1   11.151115 5 10 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2016 1    10.61238 5 10 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2017 1    10.16696 5 10 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2018 1   10.061397 5 10 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2019 1     9.95774 5 10 0 "Others"      1
            "Ireland" "Breakfast Cereals" 2020 1    9.548981 5 10 0 "Others"      1
            "Ireland" "Carbonates"        2014 0    93.63103 6 11 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2015 0    93.62852 6 11 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2016 0    93.62292 6 11 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2017 0    93.60877 6 11 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2018 0    93.58997 6 11 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2019 0    93.56568 6 11 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2020 0    93.57092 6 11 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2014 1    6.348202 6 12 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2015 1    6.350781 6 12 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2016 1     6.35649 6 12 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2017 1    6.370764 6 12 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2018 1    6.389736 6 12 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2019 1    6.414242 6 12 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2020 1    6.408684 6 12 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2014 2    .0207635 6 13 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2015 2   .02070044 6 13 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2016 2  .020589443 6 13 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2017 2   .02046161 6 13 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2018 2   .02030443 6 13 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2019 2  .020074073 6 13 0 "Soft Drinks" 2
            "Ireland" "Carbonates"        2020 2   .02039159 6 13 0 "Soft Drinks" 2
            "Ireland" "Coffee"            2014 0         100 7 14 0 "Others"      1
            "Ireland" "Coffee"            2015 0         100 7 14 0 "Others"      1
            "Ireland" "Coffee"            2016 0         100 7 14 0 "Others"      1
            "Ireland" "Coffee"            2017 0         100 7 14 0 "Others"      1
            "Ireland" "Coffee"            2018 0         100 7 14 0 "Others"      1
            "Ireland" "Coffee"            2019 0         100 7 14 0 "Others"      1
            "Ireland" "Coffee"            2020 0         100 7 14 0 "Others"      1
            "Ireland" "Concentrates"      2014 0    64.63536 8 15 0 "Soft Drinks" 2
            "Ireland" "Concentrates"      2015 0    64.63651 8 15 0 "Soft Drinks" 2
            end
            label values type Type
            label def Type 0 "Control", modify
            label def Type 1 "Sugars", modify
            label def Type 2 "Artificial sugars", modify
            label values id_test5 id_test5
            label def id_test5 2 "Baby Food", modify
            label def id_test5 3 "Baked Goods", modify
            label def id_test5 4 "Bottled Water", modify
            label def id_test5 5 "Breakfast Cereals", modify
            label def id_test5 6 "Carbonates", modify
            label def id_test5 7 "Coffee", modify
            label def id_test5 8 "Concentrates", modify
            label values product product
            label def product 1 "Others", modify
            label def product 2 "Soft Drinks", modify

            Comment


            • #7
              In the future, whenever you provide example data, make sure that it is usable. There is no United Kingdom in your data example and all values of your variable take the value 0. I can replace the UK with Ireland and introduce variation in your variable, which is what you needed to create a reproducible example. The advice remains the same, i.e., to hide the marker in your coefplot graph, you need to transform its coefficient from 0 to missing and plot using a matrix. Alternatively, add another marker to hide the marker, but this will entail changes to the xline crossing y=0 as it is interrupted by anything in the foreground. I illustrate the latter. You do not need a loop to select the interaction coefficients as they have common patterns in their names that make them identifiable and thus enable you to use wildcards.

              Code:
              set seed 02072021
              replace soft_drink=runiformint(0,1)
              reg percent i.id_test5 ib2016.year i.year##soft_drink if country=="Ireland" & type==1, robust
              coefplot, keep(20*#1*) xlab(1 "2014" 2 "2015" 3 "2016" 4 "2017" 5 "2018" 6 "2019" 7"2020") ///
              vertical title("Ireland Ingredient Soft Drink * Time Interaction Coefficients") ///
              xtitle(Years relative to 2016) baselevels omitted xline(3, lpattern("-##") lcolor(red)) ///
              mlabel(cond(@pval<.05, "***", cond(@pval<.1, "**", cond(@pval<.05, "", "")))) ///
              addplot((scatteri 0 3, msize(medlarge) mcolor(white)) (scatteri -0.25 3 0.25 3, recast(line) ///
              lcolor(red) lpattern("-##") mcolor(red))) scheme(s1color)
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	53.8 KB
ID:	1593255

              Comment


              • #8
                Hi all,

                I am trying to replicate something similar with my data. In particular, my base year is 2007 (yeard1=13) and i would like to make the coefficient points disappear and instead have only the dotted line available for 2007. The code I am using is the following:

                coefplot (est1, mcolor(gs10) ciopts(color(gs10)) keep(1.edu_f#*.yeard1)) ///
                (est1, mcolor(gs10) ciopts(color(gs10)) keep(2.edu_f#*.yeard1)) ///
                (est1, mcolor(gs6) ciopts(color(gs6))keep(3.edu_f#*.yeard1)) ///
                (est1, mcolor(gs4) ciopts(color(gs4)) keep(4.edu_f#*.yeard1 )) ///
                (est2, msymbol(O) mcolor(gs10) mfcolor(white) ciopts(color(gs10)) keep(1.edu_f#*.yeard1)) ///
                (est2, msymbol(O) mcolor(gs10) mfcolor(white) ciopts(color(gs10)) keep(2.edu_f#*.yeard1)) ///
                (est2, msymbol(O) mcolor(gs6) mfcolor(white) ciopts(color(gs6))keep(3.edu_f#*.yeard1)) ///
                (est2, msymbol(O) mcolor(gs4) mfcolor(white) ciopts(color(gs4)) keep(4.edu_f#*.yeard1 ) omitted baselevels), vertical ///
                yline(0) ///
                groups(1.edu_f#*.yeard1="{bf:Secondary education}" ///
                2.edu_f#*.yeard1="{bf:Secondary education}" ///
                3.edu_f#*.yeard1="{bf:Vocational education}" ///
                4.edu_f#*.yeard1="{bf:Tertiary education}") ///
                baselevels omitted xline(4 18 32, lpattern("-##") lcolor(black)) ///
                coeflabels(1.edu_f#10.yeard1="2004" 1.edu_f#11.yeard1="2005" 1.edu_f#12.yeard1="2006" 1.edu_f#13.yeard1="2007" 1.edu_f#14.yeard1="2008" 1.edu_f#15.yeard1="2009" 1.edu_f#16.yeard1="2010" 1.edu_f#17.yeard1="2011" 1.edu_f#18.yeard1="2012" 1.edu_f#19.yeard1="2013" 1.edu_f#20.yeard1="2014" 1.edu_f#21.yeard1="2015" 1.edu_f#22.yeard1="2016" 2.edu_f#10.yeard1="2004" 2.edu_f#11.yeard1="2005" 2.edu_f#12.yeard1="2006" 2.edu_f#13.yeard1="2007" 2.edu_f#14.yeard1="2008" 2.edu_f#15.yeard1="2009" 2.edu_f#16.yeard1="2010" 2.edu_f#17.yeard1="2011" 2.edu_f#18.yeard1="2012" 2.edu_f#19.yeard1="2013" 2.edu_f#20.yeard1="2014" 2.edu_f#21.yeard1="2015" 2.edu_f#22.yeard1="2016" 3.edu_f#10.yeard1="2004" 3.edu_f#11.yeard1="2005" 3.edu_f#12.yeard1="2006" 3.edu_f#13.yeard1="2007" 3.edu_f#14.yeard1="2008" 3.edu_f#15.yeard1="2009" 3.edu_f#16.yeard1="2010" 3.edu_f#17.yeard1="2011" 3.edu_f#18.yeard1="2012" 3.edu_f#19.yeard1="2013" 3.edu_f#20.yeard1="2014" 3.edu_f#21.yeard1="2015" 3.edu_f#22.yeard1="2016" 4.edu_f#10.yeard1="2004" 4.edu_f#11.yeard1="2005" 4.edu_f#12.yeard1="2006" 4.edu_f#13.yeard1="2007" 4.edu_f#14.yeard1="2008" 4.edu_f#15.yeard1="2009" 4.edu_f#16.yeard1="2010" 4.edu_f#17.yeard1="2011" 4.edu_f#18.yeard1="2012" 4.edu_f#19.yeard1="2013" 4.edu_f#20.yeard1="2014" 4.edu_f#21.yeard1="2015" 4.edu_f#22.yeard1="2016", notick labgap(2) angle(vertical)) ///
                graphregion(fcolor(white)) ///
                note("Base category: Primary education or below") ///
                legend(order(2 "Linear Probability Model" 8 "Linear Probability Model with Heckman correction") span)
                graph export "$coefplots/edu_father_Heckunemp_nuts2.png", width(1000) height(800) replace


                Here you can find an example of my data produced using dataex.
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input double elite float edu_f double yeard1 float occup_f byte sex_stud float nationality double lambda_1
                0 1 12 1 2 1  1.043254525784166
                0 1 22 2 2 1  .8807243479288559
                0 1 10 3 1 0                  .
                0 1 13 1 2 1 1.0431385033157994
                0 1 20 1 2 1 1.1431363900854488
                0 1 16 2 2 1  .7741537470970734
                0 1 19 1 2 1   .866481366070403
                0 1 10 1 1 1                  .
                0 1 12 1 2 1 1.0767255785213885
                0 1 14 2 2 1  .5560497434888139
                0 1 16 1 1 1  1.316855959395752
                1 1 19 2 2 1  .6619491476386039
                0 1 10 2 1 1                  .
                0 1 17 1 1 1 1.0833344553048916
                0 1 20 1 2 1 1.1097649815619703
                0 1 10 2 2 1   .747476765415923
                0 1 17 1 2 1  .8711009486511126
                0 1 15 1 2 1 1.1336815287270272
                0 1 15 2 2 1  .8407630887083043
                0 1 11 1 2 1 1.1132139174236917
                0 1 18 1 2 1  .8777161723953205
                0 1 16 1 2 1 1.0569616273737161
                0 1 22 1 2 1 1.2364493747774472
                0 1 19 1 2 1  .8551861492225585
                0 1 20 1 2 1 1.0989943315008082
                0 1 21 1 1 1 1.1512451960347456
                0 1 16 1 2 1 1.0733181421527542
                0 1 10 1 2 0                  .
                0 1 21 1 2 1  .9259909494988807
                1 1 11 3 1 1 1.0914367251015615
                1 1 13 2 2 1  .7526962805615407
                0 1 12 1 1 1                  .
                0 1 17 3 1 1  .8363555582228038
                0 1 13 1 1 1 1.2740352952515248
                0 1 18 1 2 1  .8777161723953205
                0 1 21 4 2 1  .8032719085856194
                0 1 14 1 2 0                  .
                0 1 15 1 2 1  1.117001251812017
                0 1 17 3 2 1   .647197852893997
                0 1 11 1 2 1   1.10740332761512
                0 1 22 2 1 1 1.1529680189202738
                0 1 10 2 2 1  .7695939420794652
                0 1 16 2 1 1  1.007585485227331
                0 1 20 4 2 1 1.0023564172157033
                0 1 10 2 1 0                  .
                0 1 18 2 2 1   .641209403277852
                0 1 22 1 1 1 1.4750794374420984
                0 1 15 1 1 1  1.363573755766611
                0 1 20 1 2 1 1.0989943315008082
                0 1 10 1 2 1                  .
                1 1 10 1 2 0                  .
                0 1 22 4 2 0  1.690857828103253
                0 1 10 1 2 1                  .
                0 1 20 2 2 1  .8342793927697049
                0 1 10 1 2 1 1.0234433584499347
                0 1 10 2 2 1  .7624283697123582
                0 1 10 2 2 1  .7624283697123582
                1 1 10 2 1 0                  .
                0 1 18 3 1 1  .8533380817019487
                0 1 18 1 1 1 1.1320407746133925
                0 1 10 1 1 1                  .
                0 1 12 1 1 0                  .
                0 1 13 2 2 1  .7619649639682952
                0 1 14 1 2 1   .762401348619022
                0 1 14 3 1 1  .7852146924647669
                0 1 10 1 2 1                  .
                0 1 10 1 2 1 1.0387981590177038
                0 1 14 2 2 1  .5456288354752798
                0 1 10 1 2 1                  .
                0 1 18 1 1 1 1.0880519985668655
                0 1 11 3 2 1  .8120536652138782
                0 1 18 1 2 1  .8746821619169416
                0 1 15 4 1 1 1.2671639176645504
                0 1 11 1 2 1 1.1307097492582032
                0 1 11 1 1 1  1.353322825342117
                0 1 20 4 2 1 1.0361518763063329
                0 1 10 1 2 0                  .
                0 1 10 2 1 1                  .
                0 1 10 2 2 1                  .
                0 1 13 1 2 1 1.0326071598347946
                0 1 13 2 2 1  .7526962805615407
                1 1 13 2 2 1  .7505644665615663
                0 1 22 1 1 1 1.4905547818044682
                0 1 22 2 1 1 1.0962716998100286
                1 1 10 2 2 1                  .
                0 1 22 4 2 1 1.1130851549330898
                0 1 21 1 2 1  .8829686352828467
                0 1 18 1 1 1 1.1387336465821154
                0 1 22 1 2 1 1.1766650821898716
                0 1 20 2 1 1 1.0578580054556213
                0 1 10 1 2 0                  .
                0 1 15 3 2 1  .8820169177619769
                0 1 16 4 2 1  .9688468671808836
                0 1 14 1 2 1                  .
                0 1 20 2 2 1  .8506983030599027
                0 1 14 2 2 1  .5572822979732545
                0 1 17 4 2 0                  .
                0 1 22 1 2 1 1.2954481786808116
                0 1 18 1 2 1  .9013741162536791
                0 1 11 2 1 1 1.0604316360786075
                end
                label values elite elite
                label def elite 0 "Non-elite", modify
                label def elite 1 "Elite", modify
                label values edu_f edu_f
                label def edu_f 1 "Primary education or below", modify
                label values occup_f occup_f
                label def occup_f 1 "Blue collar", modify
                label def occup_f 2 "Low skilled white collar", modify
                label def occup_f 3 "High skilled white collar", modify
                label def occup_f 4 "Unemployed", modify
                label values sex_stud sex_stud
                label def sex_stud 1 "Male", modify
                label def sex_stud 2 "Female", modify
                label values nationality nationality
                label def nationality 0 "Non-Greek", modify
                label def nationality 1 "Greek", modify
                Any help would be greatly appreciated.

                Best,
                Konstantina

                Comment


                • #9
                  You need to include the regression commands to create a reproducible example.

                  Comment


                  • #10
                    I forgot to paste the most important thing, really sorry.
                    Here they are:
                    eststo: reg elite i.edu_f#ib13.yeard1 i.edu_f i.occup_f i.sex_stud i.nationality
                    eststo: reg elite i.edu_f#ib13.yeard1 i.edu_f i.occup_f i.sex_stud i.nationality c.lambda_1#ib13.yeard1

                    Comment


                    • #11
                      Thanks. We can exploit the property that the log of 0 is undefined and use the -transform()- option. Taking the log of the base coefficients will result in missing values for these coefficients, which is exactly what we want.

                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input double elite float edu_f double yeard1 float occup_f byte sex_stud float nationality double lambda_1
                      0 1 12 1 2 1  1.043254525784166
                      0 1 22 2 2 1  .8807243479288559
                      0 1 10 3 1 0                  .
                      0 1 13 1 2 1 1.0431385033157994
                      0 1 20 1 2 1 1.1431363900854488
                      0 1 16 2 2 1  .7741537470970734
                      0 1 19 1 2 1   .866481366070403
                      0 1 10 1 1 1                  .
                      0 1 12 1 2 1 1.0767255785213885
                      0 1 14 2 2 1  .5560497434888139
                      0 1 16 1 1 1  1.316855959395752
                      1 1 19 2 2 1  .6619491476386039
                      0 1 10 2 1 1                  .
                      0 1 17 1 1 1 1.0833344553048916
                      0 1 20 1 2 1 1.1097649815619703
                      0 1 10 2 2 1   .747476765415923
                      0 1 17 1 2 1  .8711009486511126
                      0 1 15 1 2 1 1.1336815287270272
                      0 1 15 2 2 1  .8407630887083043
                      0 1 11 1 2 1 1.1132139174236917
                      0 1 18 1 2 1  .8777161723953205
                      0 1 16 1 2 1 1.0569616273737161
                      0 1 22 1 2 1 1.2364493747774472
                      0 1 19 1 2 1  .8551861492225585
                      0 1 20 1 2 1 1.0989943315008082
                      0 1 21 1 1 1 1.1512451960347456
                      0 1 16 1 2 1 1.0733181421527542
                      0 1 10 1 2 0                  .
                      0 1 21 1 2 1  .9259909494988807
                      1 1 11 3 1 1 1.0914367251015615
                      1 1 13 2 2 1  .7526962805615407
                      0 1 12 1 1 1                  .
                      0 1 17 3 1 1  .8363555582228038
                      0 1 13 1 1 1 1.2740352952515248
                      0 1 18 1 2 1  .8777161723953205
                      0 1 21 4 2 1  .8032719085856194
                      0 1 14 1 2 0                  .
                      0 1 15 1 2 1  1.117001251812017
                      0 1 17 3 2 1   .647197852893997
                      0 1 11 1 2 1   1.10740332761512
                      0 1 22 2 1 1 1.1529680189202738
                      0 1 10 2 2 1  .7695939420794652
                      0 1 16 2 1 1  1.007585485227331
                      0 1 20 4 2 1 1.0023564172157033
                      0 1 10 2 1 0                  .
                      0 1 18 2 2 1   .641209403277852
                      0 1 22 1 1 1 1.4750794374420984
                      0 1 15 1 1 1  1.363573755766611
                      0 1 20 1 2 1 1.0989943315008082
                      0 1 10 1 2 1                  .
                      1 1 10 1 2 0                  .
                      0 1 22 4 2 0  1.690857828103253
                      0 1 10 1 2 1                  .
                      0 1 20 2 2 1  .8342793927697049
                      0 1 10 1 2 1 1.0234433584499347
                      0 1 10 2 2 1  .7624283697123582
                      0 1 10 2 2 1  .7624283697123582
                      1 1 10 2 1 0                  .
                      0 1 18 3 1 1  .8533380817019487
                      0 1 18 1 1 1 1.1320407746133925
                      0 1 10 1 1 1                  .
                      0 1 12 1 1 0                  .
                      0 1 13 2 2 1  .7619649639682952
                      0 1 14 1 2 1   .762401348619022
                      0 1 14 3 1 1  .7852146924647669
                      0 1 10 1 2 1                  .
                      0 1 10 1 2 1 1.0387981590177038
                      0 1 14 2 2 1  .5456288354752798
                      0 1 10 1 2 1                  .
                      0 1 18 1 1 1 1.0880519985668655
                      0 1 11 3 2 1  .8120536652138782
                      0 1 18 1 2 1  .8746821619169416
                      0 1 15 4 1 1 1.2671639176645504
                      0 1 11 1 2 1 1.1307097492582032
                      0 1 11 1 1 1  1.353322825342117
                      0 1 20 4 2 1 1.0361518763063329
                      0 1 10 1 2 0                  .
                      0 1 10 2 1 1                  .
                      0 1 10 2 2 1                  .
                      0 1 13 1 2 1 1.0326071598347946
                      0 1 13 2 2 1  .7526962805615407
                      1 1 13 2 2 1  .7505644665615663
                      0 1 22 1 1 1 1.4905547818044682
                      0 1 22 2 1 1 1.0962716998100286
                      1 1 10 2 2 1                  .
                      0 1 22 4 2 1 1.1130851549330898
                      0 1 21 1 2 1  .8829686352828467
                      0 1 18 1 1 1 1.1387336465821154
                      0 1 22 1 2 1 1.1766650821898716
                      0 1 20 2 1 1 1.0578580054556213
                      0 1 10 1 2 0                  .
                      0 1 15 3 2 1  .8820169177619769
                      0 1 16 4 2 1  .9688468671808836
                      0 1 14 1 2 1                  .
                      0 1 20 2 2 1  .8506983030599027
                      0 1 14 2 2 1  .5572822979732545
                      0 1 17 4 2 0                  .
                      0 1 22 1 2 1 1.2954481786808116
                      0 1 18 1 2 1  .9013741162536791
                      0 1 11 2 1 1 1.0604316360786075
                      end
                      label values elite elite
                      label def elite 0 "Non-elite", modify
                      label def elite 1 "Elite", modify
                      label values edu_f edu_f
                      label def edu_f 1 "Primary education or below", modify
                      label values occup_f occup_f
                      label def occup_f 1 "Blue collar", modify
                      label def occup_f 2 "Low skilled white collar", modify
                      label def occup_f 3 "High skilled white collar", modify
                      label def occup_f 4 "Unemployed", modify
                      label values sex_stud sex_stud
                      label def sex_stud 1 "Male", modify
                      label def sex_stud 2 "Female", modify
                      label values nationality nationality
                      label def nationality 0 "Non-Greek", modify
                      label def nationality 1 "Greek", modify
                      
                      estimates clear
                      eststo: reg elite i.edu_f#ib13.yeard1 i.edu_f i.occup_f i.sex_stud i.nationality
                      eststo: reg elite i.edu_f#ib13.yeard1 i.edu_f i.occup_f i.sex_stud i.nationality c.lambda_1#ib13.yeard1
                      
                      
                      coefplot (est1, mcolor(gs10) ciopts(color(gs10)) keep(1.edu_f#*.yeard1)) ///
                      (est1, mcolor(gs10) ciopts(color(gs10)) keep(2.edu_f#*.yeard1)) ///
                      (est1, mcolor(gs6) ciopts(color(gs6))keep(3.edu_f#*.yeard1)) ///
                      (est1, mcolor(gs4) ciopts(color(gs4)) keep(4.edu_f#*.yeard1 )) ///
                      (est2, msymbol(O) mcolor(gs10) mfcolor(white) ciopts(color(gs10)) keep(1.edu_f#*.yeard1)) ///
                      (est2, msymbol(O) mcolor(gs10) mfcolor(white) ciopts(color(gs10)) keep(2.edu_f#*.yeard1)) ///
                      (est2, msymbol(O) mcolor(gs6) mfcolor(white) ciopts(color(gs6))keep(3.edu_f#*.yeard1)) ///
                      (est2, msymbol(O) mcolor(gs4) mfcolor(white) ciopts(color(gs4)) keep(4.edu_f#*.yeard1 )), vertical ///
                      yline(0) ///
                      groups(1.edu_f#*.yeard1="{bf:Secondary education}" ///
                      2.edu_f#*.yeard1="{bf:Secondary education}" ///
                      3.edu_f#*.yeard1="{bf:Vocational education}" ///
                      4.edu_f#*.yeard1="{bf:Tertiary education}") ///
                      baselevels omitted xline(4 18 32, lpattern("-##") lcolor(black)) ///
                      coeflabels(1.edu_f#10.yeard1="2004" 1.edu_f#11.yeard1="2005" 1.edu_f#12.yeard1="2006" 1.edu_f#13.yeard1="2007" 1.edu_f#14.yeard1="2008" 1.edu_f#15.yeard1="2009" 1.edu_f#16.yeard1="2010" 1.edu_f#17.yeard1="2011" 1.edu_f#18.yeard1="2012" 1.edu_f#19.yeard1="2013" 1.edu_f#20.yeard1="2014" 1.edu_f#21.yeard1="2015" 1.edu_f#22.yeard1="2016" 2.edu_f#10.yeard1="2004" 2.edu_f#11.yeard1="2005" 2.edu_f#12.yeard1="2006" 2.edu_f#13.yeard1="2007" 2.edu_f#14.yeard1="2008" 2.edu_f#15.yeard1="2009" 2.edu_f#16.yeard1="2010" 2.edu_f#17.yeard1="2011" 2.edu_f#18.yeard1="2012" 2.edu_f#19.yeard1="2013" 2.edu_f#20.yeard1="2014" 2.edu_f#21.yeard1="2015" 2.edu_f#22.yeard1="2016" 3.edu_f#10.yeard1="2004" 3.edu_f#11.yeard1="2005" 3.edu_f#12.yeard1="2006" 3.edu_f#13.yeard1="2007" 3.edu_f#14.yeard1="2008" 3.edu_f#15.yeard1="2009" 3.edu_f#16.yeard1="2010" 3.edu_f#17.yeard1="2011" 3.edu_f#18.yeard1="2012" 3.edu_f#19.yeard1="2013" 3.edu_f#20.yeard1="2014" 3.edu_f#21.yeard1="2015" 3.edu_f#22.yeard1="2016" 4.edu_f#10.yeard1="2004" 4.edu_f#11.yeard1="2005" 4.edu_f#12.yeard1="2006" 4.edu_f#13.yeard1="2007" 4.edu_f#14.yeard1="2008" 4.edu_f#15.yeard1="2009" 4.edu_f#16.yeard1="2010" 4.edu_f#17.yeard1="2011" 4.edu_f#18.yeard1="2012" 4.edu_f#19.yeard1="2013" 4.edu_f#20.yeard1="2014" 4.edu_f#21.yeard1="2015" 4.edu_f#22.yeard1="2016", notick labgap(2) angle(vertical)) ///
                      graphregion(fcolor(white)) ///
                      note("Base category: Primary education or below") ///
                      transform(*13.*= log(@)) ///
                      legend(order(2 "Linear Probability Model" 8 "Linear Probability Model with Heckman correction") span)
                      *graph export "$coefplots/edu_father_Heckunemp_nuts2.png", width(1000) height(800) replace
                      Res.:

                      Click image for larger version

Name:	Graph.png
Views:	1
Size:	38.4 KB
ID:	1744883


                      Comment


                      • #12
                        Thank you so much Andrew! That is great

                        Comment

                        Working...
                        X