Announcement

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

  • Graph twoway with controls

    Hello - I'm sorry in advance if this is a basic question. I'm a beginner in Stata.

    I'm trying to graph the wage trend for two groups - 1 & 2 - as to show there is a parallel trend for the period 2005-2010.

    I used the code below:
    Code:
    graph twoway (line logwage year if group==1) (line logwage year if group==2), /// legend(label(1 G1) label(2 G2))
    However, I would also like to check the results in a graph controlling for the variables I have available (education, tenure, sector, region,...). The same way we would do when we include more variables in a regression, but applied to graph twoway. Is there a way to do this?


    Thank you in advance.

  • #2
    Hi Mariana,

    As I understand, you wish to plot the linearly predicted values of logwage for each group, controlling for a set of covariates. To do this, you can use the -predict- command after you've run the models:
    Code:
    reg logwage education tenure sector region [...] if group == 1
    predict xb_group1, xb
    
    reg logwage education tenure sector region [...] if group == 2
    predict xb_group2, xb
    You can then in turn plot the predicted values in the two new variables:
    Code:
    twoway (line xb_group1 year) (line xb_group2 year), legend(label(1 G1) label(2 G2))

    Comment


    • #3
      The predict command did the trick.
      Thank you.

      Comment


      • #4
        I came across this post while searching for a solution for a similar issue. However, using predict does not work as a fix in my case.

        I want to plot a twoway graph from a linear regression model that predicts the probability to be employed over age interacted with education while controlling for cohort effects. The resulting graph should include two lines (education separates two groups) and this works fine as long as I do not include any control. However, as soon as I include controls in the regression, the lines in the graph start to look funky (i.e. the lines become thick bars and there is something that looks like missing pixels at the beginning and at the end of those bars)

        I use the following code:

        Code:
         
        reg emp c.age##i.educ c.cohort
        predict pr, xb
        graph twoway line pr age if educ==0 || line pr age if educ==1
        And a picture of the graph that I get.


        Click image for larger version

Name:	faulty graph.png
Views:	1
Size:	491.6 KB
ID:	1650599

        Comment

        Working...
        X