Announcement

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

  • Creating tables and graphs on data relating to both the survey respondent and their partner

    Hi Statalist.

    I would appreciate a hand with how to create a scatterplot presenting data on both the respondent and their partner for categorical variables, such as life satisfaction scores or self-reported health scores. I would like to do this for one wave of data, then present this for several waves of data. Based on my search in Statalist and Stata help, etc, I have not yet found how I can achieve this.

    Thank you in advance.
    Chris

  • #2
    I don't quite understand what your question is. Do you have problems deciding what kind of graph or table to use to visualize this or is it more "mechanical" in the sense that you know what you want but have trouble telling Stata how to do that?

    For the former you can look at the bottom of this post for a visual representation of a three way table (in your case that could be for example the table of own life satisfaction versus partner's life satisfaction by wave). At the very bottom is a reference to an article by Nick Cox that can provide more inspiration concerning this type of display. https://www.statalist.org/forums/for...tion-of-graphs

    If you problem is mechanical, then we need an extract of your data (see help dataex) and an exact description of what you want to do.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you Maarten Buis. Yes the problem relates to finding an appropriate graph to visualise the relationships in my data. I was using a twoway scatter, but haven't found it helpful so far - maybe due to the kind of data I have (much of which relate to responses based on LIkert scales (1-10, 1-5) for both the respondent and their partner. I haven't been successful using twby yet so I must be doing something wrong. Anyway, I'll work on it. If you have any suggestions on graph types, I would be appreciative.

      Kind regards,
      Chris

      Comment


      • #4
        Originally posted by Chris Boulis View Post
        I haven't been successful using twby yet so I must be doing something wrong.
        Can you give us an example of what you want to do exactly, including an extract from your data (see help dataex)? It is very hard for us to imagine what is going wrong from that one statement. A good question contains an exact description of what you tried to do, what you did to achieve that (the actual code), how the output of that code did not satisfy your needs, and some example data.

        This could be helpful for you, as you can get an answer. It is also genuinly useful for me (the author of twby) to see what a user thinks should work. Maybe I need to add options or improve the help file.
        Last edited by Maarten Buis; 02 Jan 2020, 04:24.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          In a concurrent thread you gave a small data example and implied that negative codes were various kinds of missing. From that and from the link given in #2 it follows that tabplot gives one of several alternatives.

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input float(id imp p_imp)
          100018  5  1
          100019  1  5
          100023 10 10
          100024 10 10
          100029  5  1
          100030  1  5
          100038  5  0
          100039  0  5
          100042  2  4
          100043  4  2
          100048 -8 -8
          100049 -8 -8
          100052  2  7
          100053  7  2
          100055 -8  3
          100057  3  1
          end
          
          * ssc install tabplot 
          set scheme s1color 
          tabplot imp p_imp if min(imp, p_imp) > 0, showval bfcolor(green*0.2)
          Click image for larger version

Name:	boulis.png
Views:	1
Size:	14.8 KB
ID:	1530483


          As documented at #12 of https://www.statalist.org/forums/for...updated-on-ssc the latest version of tabplot is (still) that at SSC.

          In a fuller dataset presumably more of the cells would be populated and the aspect ratio of the graph could be tweaked suitably.

          Comment


          • #6
            Originally posted by Chris Boulis View Post
            Yes the problem relates to finding an appropriate graph to visualise the relationships in my data. I was using a twoway scatter, but haven't found it helpful so far - maybe due to the kind of data I have (much of which relate to responses based on LIkert scales (1-10, 1-5) for both the respondent and their partner. Anyway, I'll work on it. If you have any suggestions on graph types, I would be appreciative.
            Above I discussed the problems with the coding part of your question, but the substantive part is also difficult:

            Put yourself in our position: Prior to your question we knew nothing about you or your project. All we know is what is in this quesiton. Apperently, you look at the answer I gave you and the links (in particular the article by Nick Cox) and did not find them satisfactory. We don't know why. That is not a lot to go on.

            Asking questions can be an iterative process, but we need to make sure that each iteration adds something. A simple way to achieve that is to tell us why the previous answer did not help you. It is very hard for us to determine what it is exactly what you want, and the reasons why the previous answers were unhelpful to you can often be very informative for us, and help pin down the "real" question. Alternatively the reasons may show that you misunderstood the previous answer and we could clarify that. Either way we can make progress.

            What would also be helpful is if you told us why you want to create these graphs; What are they supposed to show? What is the story you want to tell with them?
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              Thank you very much for your responses Maarten Buis. My apologies for not clarifying my question well initially. I will try to clarify further here. I want to identify the most appropriate graph types to help me visualise relationships in data I have. I am working with panel data based on survey questionnaires over many waves. I am particularly interested in changes in behaviour over time for the same respondents (and their partners). An example, is to see the life satisfaction scores for both the respondent and their partner and see if these scores are influenced by their marital status and whether or not they are religious, for example (there are many other potential explanatory variables of course). The following is an excerpt of some data I am working with. I've included three pairs of variables (each pair represents responses for the respondent and their partner for the given variable): life satisfaction (scale 1 to 10), marital status (scale 1-6) and whether one is religious or not (dummy where 0=not religious). All negative variables relate to non-responses of some form.
              Code:
              * Example generated by -dataex-. To install: ssc install dataex
              clear
              input float(sat p_sat marstat p_marstat relig p_relig)
                8   7   1   1 1 1
                7   8   1   1 1 1
                8   8   1   1 1 1
                8   8   1   1 1 1
                8   8   1   1 1 1
                8   8   1   1 1 1
                8   8   1   1 1 1
                8   8   1   1 1 1
                9  10   2   2 1 1
                7   5   1   1 1 .
                5   7   1   1 0 1
                8   9   1   1 1 1
                9   8   1   1 1 1
               -4   9   1   1 1 1
                9  -4   1   1 1 1
               10  10   2   2 1 .
               10  10   2   2 0 1
                8   9   1   1 1 1
                9   8   1   1 1 1
                7   8   1   1 . .
                8   7   1   1 . .
                8   7   1   1 1 1
                7   8   1   1 1 1
                8   7   1   1 . 1
                9   8   1   1 1 1
                8   9   1   1 1 1
              -10   7 -10   1 . 1
                7 -10   1 -10 1 .
                8  10   1   1 0 0
               10   8   1   1 0 0
                5   9   1   1 0 1
                9   5   1   1 1 .
                7   7   2   2 0 1
                7   7   2   2 1 .
                7   8   1   1 0 1
                8   7   1   1 1 .
                4   5   1   1 1 1
                5   4   1   1 1 1
                8   7   2   2 . .
               10   9   1   1 1 1
                9  10   1   1 1 1
                8   9   1   1 1 1
                9   8   1   1 1 1
                8   8   1   1 1 .
                8   8   1   1 . 1
                5 -10   2 -10 0 0
              -10   8 -10   2 . 1
                8 -10   2 -10 1 .
                9   7   1   1 0 1
                7   9   1   1 1 .
               end
              I need to be able to include restrictions, such as restricting which wave (or waves) of data I want to use, whether or not I want to specify a given marital status, ie. those married, and so on. I am reading through the link you provided me to Nick Cox's paper "Multiple bar charts in table form" and I am also looking at others he written to help me. I hope this helps. Thank you again.

              Comment


              • #8
                Thank you for that Nick Cox. I will read up on how to make various adjustments to the graphs, for example, to have the numbers running from 0-10 out on the Y-axis as it does with the x-axis. I have your Speaking Stata paper "Multiple bar charts in table form" to read and your post "tabplot updated on ssc" (12 Apr 2016, 09:56) which will no doubt help me become more acquainted with tabplot. I'm keen to explore this technique. Thank you again.

                Comment


                • #9
                  Options which may help are yreverse yasis xasis
                  Last edited by Nick Cox; 03 Jan 2020, 04:19.

                  Comment


                  • #10
                    Thank you Nick Cox

                    Comment


                    • #11
                      Using the example data listed in #5 and #7, I would like to create a table based on three categories: category "low" which accounts for responses 1-3, "medium" 4-6, and "high" 7-10 for both "imp" and "p_imp", for example. I then want to table this with row headings such as "both high" "both medium" and "both low" by frequency and proportion (% of the whole) for waves 4, 7, 10, 14, 18. I managed to get a table similar to what I want but only for wave 4 using
                      Code:
                      tabulate reli p_reli (#5) if wave==4 & marstat==1 (married) | marstat==2 (de-facto) (#7), cell
                      It would be interesting to have a table that combines the two marital status types and another that shows the results by the two different marital status types for the stated waves of data if that is possible. Any guidance on how I could develop such a table is very much appreciated.

                      Best regards, Chris

                      Comment


                      • #12
                        This may help:

                        Code:
                        * Example generated by -dataex-. To install: ssc install dataex
                        clear
                        input float(sat p_sat marstat p_marstat relig p_relig)
                          8   7   1   1 1 1
                          7   8   1   1 1 1
                          8   8   1   1 1 1
                          8   8   1   1 1 1
                          8   8   1   1 1 1
                          8   8   1   1 1 1
                          8   8   1   1 1 1
                          8   8   1   1 1 1
                          9  10   2   2 1 1
                          7   5   1   1 1 .
                          5   7   1   1 0 1
                          8   9   1   1 1 1
                          9   8   1   1 1 1
                         -4   9   1   1 1 1
                          9  -4   1   1 1 1
                         10  10   2   2 1 .
                         10  10   2   2 0 1
                          8   9   1   1 1 1
                          9   8   1   1 1 1
                          7   8   1   1 . .
                          8   7   1   1 . .
                          8   7   1   1 1 1
                          7   8   1   1 1 1
                          8   7   1   1 . 1
                          9   8   1   1 1 1
                          8   9   1   1 1 1
                        -10   7 -10   1 . 1
                          7 -10   1 -10 1 .
                          8  10   1   1 0 0
                         10   8   1   1 0 0
                          5   9   1   1 0 1
                          9   5   1   1 1 .
                          7   7   2   2 0 1
                          7   7   2   2 1 .
                          7   8   1   1 0 1
                          8   7   1   1 1 .
                          4   5   1   1 1 1
                          5   4   1   1 1 1
                          8   7   2   2 . .
                         10   9   1   1 1 1
                          9  10   1   1 1 1
                          8   9   1   1 1 1
                          9   8   1   1 1 1
                          8   8   1   1 1 .
                          8   8   1   1 . 1
                          5 -10   2 -10 0 0
                        -10   8 -10   2 . 1
                          8 -10   2 -10 1 .
                          9   7   1   1 0 1
                          7   9   1   1 1 .
                         end
                         
                        label def generic 1 low 2 medium 3 high 
                         
                        foreach v in sat p_sat marstat p_marstat relig p_relig { 
                            gen `v'2 = cond(inrange(`v', 1, 3), 1,  ///
                                       cond(inrange(`v', 4, 6), 2,  ///
                                       cond(inrange(`v', 7, 10), 3, .)))
                            label val `v'2 generic 
                        } 
                        
                        tab sat2 p_sat2 
                        
                        egen gsat = group(sat2 p_stat2), label 
                        tab gsat

                        Comment


                        • #13
                          Thank you Nick Cox. That is awesome . I also want to be able to discern whether other variables, such as being married (marstat==1) or de-facto (marstat==2) and/or if religious (relig==1) or not (relig==0) influence certain outcomes, such as a "low low" or "high high". I know I can add 'if' statements to the end of the 'tab' line, such as "if marstat==1 & relig==1, but was wondering if you could show me a more concise/eloquent way of doing this? Kind regards, Chris
                          Last edited by Chris Boulis; 09 Jan 2020, 19:06.

                          Comment


                          • #14
                            #12 showed a way to produce composite variables: see also https://www.stata-journal.com/sjpdf....iclenum=dm0034

                            I don't think you need any new technique you haven't used already.

                            For example, if you wanted to tabulate gsat from #12 against anything else, then

                            Code:
                            tabulate gsat marstat
                            Or you could tabulate two composite variables, and so on. Or you could have a series of tables. For my part, most three-way tables are too hard to think about, and I switch to graphs. I still recall the explosion of interest in loglinear models 40 or so years ago, although they seem to have faded in popularity just as rapidly.

                            Comment


                            • #15
                              Thank you Nick Cox.

                              Further to my initial question, I would like to ask if there was a way we can ensure consistency in the scales of the axes of graphs? I want to compare two graphs but sometimes because of the nature of the data (large difference in the values) the scales end up very different, thereby reducing the ease with which one can compare them. The following is an example of such data. This sample data is from a panel and contains three sets of variables with each set relating to both the respondent and their partner. In the first graph I would like to graph vol p_vol for married couples and compare with vol p_vol for defacto couples.

                              I was using tabplot, but not sure if there is a function to control for scales. I tried using 'xlabel' and 'ylabel', but as you can see, not successfully. The code I used was:
                              Code:
                              tabplot vol p_vol if marr==1, showval bfcolor(green*0.2) yreverse legend(cols(1)) scheme(s1color) ytitle(Total Hours/Mins) title(Vol (hrs/mins:marr), size(medsmall)) ylabel(0(1)10) xtitle(Total Hours/Mins) xlabel(1(1)10) name(vol_marr, replace)
                              tabplot vol p_vol if defact==1, showval bfcolor(green*0.2) yreverse legend(cols(1)) scheme(s1color) ytitle(Total Hours/Mins) title(Vol (hrs/mins:defact), size(medsmall)) ylabel(0(1)10) xtitle(Total Hours/Mins) xlabel(1(1)10) name(vol_defact, replace)
                              I'm not sure if I need all the code used (such as 'legend(cols(1))' and 'size(medsmall))' or if I am missing useful code to better present my graphs so feedback on this would also be appreciated.

                              Code:
                              * Example generated by -dataex-. To install: ssc install dataex
                              clear
                              input float(vol p_vol marr p_marr defact p_defact)
                              2 10 1 1 . .
                              6  5 1 1 . .
                              2  3 1 1 . .
                              6  2 1 1 . .
                              2  3 1 1 . .
                              5  0 1 1 . .
                              1  4 1 1 . .
                              5  4 1 1 . .
                              4  0 1 1 . .
                              4  0 1 1 . .
                              4  0 1 1 . .
                              5  0 1 1 . .
                              3  2 1 1 . .
                              2  6 1 1 . .
                              3  2 1 1 . .
                              0  5 1 1 . .
                              4  1 1 1 . .
                              4  5 1 1 . .
                              0  4 1 1 . .
                              0  4 1 1 . .
                              0 2 . . 1 1
                              3  . . . 1 .
                              2  0 1 1 . .
                              2  0 . . 1 1
                              2  . . . 1 1
                              0  4 1 1 . .
                              2  0 . . 1 1
                              2  . . . 1 1
                              0  5 1 1 . .
                              2  0 1 1 . .
                              1  0 1 1 . .
                              2  0 . . 1 1
                              2  1 . . 1 1
                              1  0 1 1 . .
                              2  3 1 1 . .
                              5  0 1 1 . .
                              3  2 1 1 . .
                              0  5 1 1 . .
                              0 5 . . 1 1
                              4  . . . 1 .
                              2  0 1 1 . .
                              2  0 . . 1 1
                              2  . . . 1 1
                              2  0 1 1 . .
                              1  0 1 1 . .
                              3  0 1 1 . .
                              6  0 1 1 . .
                              1  1 1 1 . .
                              1  2 1 1 . .
                              8  1 1 1 . .
                              6  1 1 1 . .
                              end

                              Comment

                              Working...
                              X