Announcement

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

  • How to plot these graphs?

    Dear all,

    I want to plot two graphs shown pictures below. I would appreciate if anyone can help me out.

    Figure 1 displays the cross-national bivariate relationship between social rights (independent variable) and self-rated health (dependent variable), while Figure 2 depict bivariate relationships between self-rated health and social rights,
    with the sample stratified according to sex (men versus women).

    As for a data example, I have 16 countries and please note that self-rated health and social right are measured as aggregated variables and, thus, each country has only one value for each of these two variables. In my case, self-rated health is labeled as health and social right is labeled as social_right. Since -dataex- command allows for only 100 observations while I have 16 countries, so to provide as much variation as possible I attached an excel file containing an example of my data.

    Figure 1:
    Click image for larger version

Name:	Figure 1.png
Views:	1
Size:	161.5 KB
ID:	1618380

    Figure 2:
    Click image for larger version

Name:	Figure 2.png
Views:	1
Size:	196.6 KB
ID:	1618381

    Thank you.
    Attached Files

  • #2
    Since -dataex- command allows for only 100 observations ....
    -dataex- has options. The option count(100) is default, but can be changed to something else.

    To me this looks like a scatter plot with an overlaid line plot.
    For the specifically linear and quadratic polynomial fit there are special twoway graphs lfit and qfit (see help twoway).

    If this was an arbitrary y=F(x), I'd built an additional series for a smooth plotting (say 100 or 300 points connected, without markers).

    Comment


    • #3
      Originally posted by Sergiy Radyakin View Post
      -dataex- has options. The option count(100) is default, but can be changed to something else.

      To me this looks like a scatter plot with an overlaid line plot.
      For the specifically linear and quadratic polynomial fit there are special twoway graphs lfit and qfit (see help twoway).

      If this was an arbitrary y=F(x), I'd built an additional series for a smooth plotting (say 100 or 300 points connected, without markers).
      Thank you for the useful advice. I added a data example using dataex command below. Based on your suggestions, I was able to make Figure 1 but had no ideas how to add equations and R-squared. Any advice on this issue as well as how to plot Figure 2? Thank you.

      code for Figure 1 without equations and R-squared
      Code:
      gr twoway (scatter health social_right, mlabel(country)) ///
                (lfit health social_right) ///
                (qfit health social_right), legend(off)
      Data
      Code:
      clear
      input byte gender float(country health social_right)
      1 14 .19994067  .4635915
      0  6 .35391805 .50664204
      0 15  .2241287  .5768634
      0 14 .19994067  .4635915
      1 12  .3555608  .4356601
      0 10 .20808697 .50191545
      0  6 .35391805 .50664204
      1 10 .20808697 .50191545
      1 10 .20808697 .50191545
      1  3  .3243201  .5785787
      1  9  .3173567  .5197403
      1 10 .20808697 .50191545
      1 15  .2241287  .5768634
      1 15  .2241287  .5768634
      0  5  .2988163  .6072752
      1 13 .28222182  .6227592
      0  6 .35391805 .50664204
      1 15  .2241287  .5768634
      1  7   .323873  .4987507
      0  1  .1516629  .5622664
      0  1  .1516629  .5622664
      0  1  .1516629  .5622664
      1  2 .14520106  .5371106
      1  1  .1516629  .5622664
      1  5  .2988163  .6072752
      1 10 .20808697 .50191545
      1 12  .3555608  .4356601
      1  1  .1516629  .5622664
      0 13 .28222182  .6227592
      0 12  .3555608  .4356601
      0  2 .14520106  .5371106
      0 10 .20808697 .50191545
      1  1  .1516629  .5622664
      1 14 .19994067  .4635915
      0 14 .19994067  .4635915
      1 14 .19994067  .4635915
      1 12  .3555608  .4356601
      0 14 .19994067  .4635915
      0  4 .19421934  .5882612
      0 13 .28222182  .6227592
      1  1  .1516629  .5622664
      1  4 .19421934  .5882612
      1  9  .3173567  .5197403
      0  1  .1516629  .5622664
      0  5  .2988163  .6072752
      1  7   .323873  .4987507
      1 15  .2241287  .5768634
      1  1  .1516629  .5622664
      0  7   .323873  .4987507
      1 15  .2241287  .5768634
      1  1  .1516629  .5622664
      1  2 .14520106  .5371106
      1 12  .3555608  .4356601
      1 14 .19994067  .4635915
      1 10 .20808697 .50191545
      1 10 .20808697 .50191545
      0 11  .2531572  .6177648
      1  3  .3243201  .5785787
      0  9  .3173567  .5197403
      1 14 .19994067  .4635915
      1 12  .3555608  .4356601
      1  5  .2988163  .6072752
      0 10 .20808697 .50191545
      1  1  .1516629  .5622664
      0  1  .1516629  .5622664
      1  1  .1516629  .5622664
      1  4 .19421934  .5882612
      0  2 .14520106  .5371106
      0  7   .323873  .4987507
      0  1  .1516629  .5622664
      1  1  .1516629  .5622664
      0  6 .35391805 .50664204
      1 14 .19994067  .4635915
      0 11  .2531572  .6177648
      1 15  .2241287  .5768634
      1  5  .2988163  .6072752
      1 13 .28222182  .6227592
      0  1  .1516629  .5622664
      1  1  .1516629  .5622664
      1  1  .1516629  .5622664
      0 11  .2531572  .6177648
      1 15  .2241287  .5768634
      1  3  .3243201  .5785787
      1 11  .2531572  .6177648
      0  2 .14520106  .5371106
      0 14 .19994067  .4635915
      1 13 .28222182  .6227592
      0  4 .19421934  .5882612
      0 10 .20808697 .50191545
      1  6 .35391805 .50664204
      1  5  .2988163  .6072752
      0  4 .19421934  .5882612
      1  7   .323873  .4987507
      0 10 .20808697 .50191545
      0 12  .3555608  .4356601
      1  1  .1516629  .5622664
      1 13 .28222182  .6227592
      0 16  .4380161  .5368937
      0  4 .19421934  .5882612
      1  8  .3230132  .5185623
      1 15  .2241287  .5768634
      1  6 .35391805 .50664204
      0 13 .28222182  .6227592
      0  5  .2988163  .6072752
      1  1  .1516629  .5622664
      0 15  .2241287  .5768634
      1  4 .19421934  .5882612
      1 12  .3555608  .4356601
      1  1  .1516629  .5622664
      0 10 .20808697 .50191545
      1 12  .3555608  .4356601
      1  7   .323873  .4987507
      1  2 .14520106  .5371106
      1 14 .19994067  .4635915
      0  6 .35391805 .50664204
      0 10 .20808697 .50191545
      0 15  .2241287  .5768634
      1  1  .1516629  .5622664
      1 11  .2531572  .6177648
      0  9  .3173567  .5197403
      0  9  .3173567  .5197403
      1 13 .28222182  .6227592
      0 10 .20808697 .50191545
      0  2 .14520106  .5371106
      0 15  .2241287  .5768634
      0 11  .2531572  .6177648
      0  1  .1516629  .5622664
      1 10 .20808697 .50191545
      1  3  .3243201  .5785787
      1  6 .35391805 .50664204
      0 14 .19994067  .4635915
      1  3  .3243201  .5785787
      0 14 .19994067  .4635915
      0  5  .2988163  .6072752
      0  1  .1516629  .5622664
      0 12  .3555608  .4356601
      1 16  .4380161  .5368937
      1  6 .35391805 .50664204
      0 15  .2241287  .5768634
      0 10 .20808697 .50191545
      1 14 .19994067  .4635915
      1  1  .1516629  .5622664
      1  1  .1516629  .5622664
      0  8  .3230132  .5185623
      1  7   .323873  .4987507
      1 12  .3555608  .4356601
      1  7   .323873  .4987507
      1  5  .2988163  .6072752
      1  1  .1516629  .5622664
      1 10 .20808697 .50191545
      0  3  .3243201  .5785787
      1  1  .1516629  .5622664
      1 10 .20808697 .50191545
      1  4 .19421934  .5882612
      1  5  .2988163  .6072752
      1 15  .2241287  .5768634
      0  1  .1516629  .5622664
      0  7   .323873  .4987507
      0 15  .2241287  .5768634
      0  7   .323873  .4987507
      0  5  .2988163  .6072752
      1  8  .3230132  .5185623
      1  2 .14520106  .5371106
      0 10 .20808697 .50191545
      0  8  .3230132  .5185623
      0 12  .3555608  .4356601
      1 11  .2531572  .6177648
      1 10 .20808697 .50191545
      1 15  .2241287  .5768634
      0 15  .2241287  .5768634
      0 13 .28222182  .6227592
      0  2 .14520106  .5371106
      0 14 .19994067  .4635915
      1  8  .3230132  .5185623
      1 10 .20808697 .50191545
      1  1  .1516629  .5622664
      1 10 .20808697 .50191545
      1 11  .2531572  .6177648
      0  3  .3243201  .5785787
      0 13 .28222182  .6227592
      0 10 .20808697 .50191545
      1  5  .2988163  .6072752
      1 16  .4380161  .5368937
      1 10 .20808697 .50191545
      1 12  .3555608  .4356601
      1  1  .1516629  .5622664
      0  4 .19421934  .5882612
      0  7   .323873  .4987507
      1  4 .19421934  .5882612
      0 13 .28222182  .6227592
      1  8  .3230132  .5185623
      1 12  .3555608  .4356601
      1  7   .323873  .4987507
      0  1  .1516629  .5622664
      1  9  .3173567  .5197403
      1  5  .2988163  .6072752
      1  1  .1516629  .5622664
      1  2 .14520106  .5371106
      1  7   .323873  .4987507
      1 15  .2241287  .5768634
      end
      label values country countryn
      label def countryn 1 "JP", modify
      label def countryn 2 "Aus", modify
      label def countryn 3 "Ger", modify
      label def countryn 4 "Swe", modify
      label def countryn 5 "NL", modify
      label def countryn 6 "Spa", modify
      label def countryn 7 "Ita", modify
      label def countryn 8 "Fra", modify
      label def countryn 9 "Den", modify
      label def countryn 10 "Gre", modify
      label def countryn 11 "Swi", modify
      label def countryn 12 "Bel", modify
      label def countryn 13 "Isr", modify
      label def countryn 14 "Cze", modify
      label def countryn 15 "Pol", modify
      label def countryn 16 "Ire", modify

      Comment


      • #4
        Maarten Buis has provided an example of how to display the fit equations on the graph a while ago. Refer to:
        https://www.stata.com/statalist/arch.../msg00362.html

        As for the second graph - this is two sets of the same graphs, just keep on overlaying them within the same twoway, but use the if condition to only obtain the points you need.

        Code:
        twoway (scatter health social_right if gender==0, mlabel(country) msymbol(d) color(red)) || ///
        (scatter health social_right if gender==1, mlabel(country) msymbol(d) color(navy))

        Comment


        • #5
          Dear Professor Sergiy,

          Thanks for your useful suggestions. I appreciate that. Regrading the second graph, however, I was unable to make a similar graph as in #1 using code provided in #4. I understand that there may need some code adjustments to get what I need. I would appreciate if you or someone might have further advice on this.

          Thank you.

          Comment

          Working...
          X