Announcement

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

  • Plotting categorical variables

    Hi all,

    can any of you tel me how I can get ht below graph?

    My rep variable is life satisfaction and the independent include - marital status, age, employment status, year dummies, log income, log education.

    I want to make three graphs consequently for married, singles and the ones that change their marital status from single to married. For the last one I assume an RD plot will be needed. But in general, how can I plot life satisfaction which is categorical variable to show exactly the categories (as whoso on the photo). I have limited the sample to married and single and the age I need.

    Thanks you!

    Regards,
    Gabriela
    Attached Files

  • #2
    Dear Gabriela,

    Please consult the FAQ page first, and read the paragraph: 12.2 What to say about your data

    Next: use dataex to provide some sample of your data (i.e. variables).
    How to create such a graph is close to impossible to explain without some data being provided.

    All the best,
    Eric
    http://publicationslist.org/eric.melse

    Comment


    • #3
      Eric provided the best approach.

      Just as a side note, you may thing about using - margins - followed by - marginsplot - commands. The Stata Manual will provide nice examples.
      Best regards,

      Marcos

      Comment


      • #4
        The odds are you'll get a truly insightful reply, provided you act according to the advice given in #2.

        The more you get used to the forum, the more you'll understand how important it is to provide the necessary information.

        In short, please read the FAQ, particularly the excerpt pointed out by Eric. Thanks.
        Best regards,

        Marcos

        Comment


        • #5
          Hi all,

          as said I am running panel data regression analysis online satisfaction and marital status covering 32 years balanced dataset but with missing observations. My aim is to replicate the twoway regression analysis graph as shown above in the my first post.

          What I do is to create mean value for life satisfaction fo the certain marital status (single and married) and then plot them- However, my issue comes when I need to add the singles who marry later in life. When I use the code as shown below and run the twoway plotting I don't get married and married later in life overlain and I should. As shown not he graph above I want to show the 'threshold'. When I create the mean for 'married later in life' and I check my code I realize that it is taking into consideration the mean for all reported values for life satisfaction if the status changes but taking the mean when the person in single as well as married. I want to isolate that and take the mean of people who report marrying later inline, however considering only their evaluation of when they were single excluding 3 years before marriage. For example: a person got married in 2013 and was reporting being single before that. hence I want to include this person in my graph plot considering the mean of his values up to year 2010).

          Moreover, the authors which paper I am replicating say that they 'control fo other variable such as age, employment and so on'. How do I do that? Does it mean just restricting the sample to the variables I want to control for? I am not aware of any command in twoway to control for other variables than the represented ones.

          bysort pid (age): egen Mean = mean(lifesatis) if marstatus==1
          bysort age: egen Mean_ = mean(Mean) if marstatus==1
          label var Mean_ "Married"


          bysort pid (age): egen Mean__ = mean(lifesatis) if marstatus==2
          bysort age: egen Mean___ = mean(Mean__) if marstatus==2
          label var Mean___ "Single"

          * restricting the sample to single people who are 4 years aways from marriage
          bys pid (syear):egen s= max(marstatus[_n]==2 & marstatus[_n+1]==2 & marstatus[_n+2]==2 & marstatus[_n+3]==1 &_n<_N)

          bysort pid (age): egen M = mean(lifesatis) if s==1
          bysort age: egen M_ = mean(M) if s==1
          label var M_ "Married later in life"

          twoway (connected Mean_ age if age <=60 & age>=20) (connected Mean___ age if age <=60 & age>=20) (connected M_ age if age <=60 & age>=20)


          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input float s long pid byte(lifesatis marstatus sex newd11105)
          0 101  8 1 1 1
          0 101  8 1 1 1
          0 101 10 1 1 1
          0 101  8 1 1 1
          0 101  8 1 1 1
          0 101  8 1 1 1
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 101  . . . .
          0 102  8 1 2 1
          0 102  8 1 2 1
          0 102  9 1 2 1
          0 102  8 1 2 1
          0 102  9 1 2 1
          0 102 10 1 2 1
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 102  . . . .
          0 103  8 2 1 3
          0 103  8 2 1 1
          0 103  7 2 1 1
          0 103  7 2 1 1
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 103  . . . .
          0 201 10 . 2 1
          0 201 10 . 2 1
          0 201  9 . 2 1
          0 201 10 . 2 1
          end
          label values lifesatis p11101
          label def p11101 10 "[10] Completely satisfied    10", modify
          label values marstatus d11104
          label def d11104 1 "[1] Married        1", modify
          label def d11104 2 "[2] Single         2", modify
          label values sex d11102ll
          label def d11102ll 1 "[1] Male           1", modify
          label def d11102ll 2 "[2] Female         2", modify

          Kind regards,
          Gabriela

          Comment

          Working...
          X