Announcement

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

  • Using a graph for a binary variable

    Hello all,

    I have a variable, Financial Aid (0 = not on Financial Aid, 1 = on Financial Aid), and I'd like to show the percent (%) of students on Financial Aid, by Race. How would I go about doing this? I'm relatively new to Stata, so haven't tried many options - I know that I'd have to use the by() option for Race, but not much else. Right now, the graph that I am creating is also including the 0s (IOW, people not on financial aid), which is pretty annoying. Also, I'd like a bar graph, as that is the way I'd to represent my data, with percent (%) on the y-axis, and the different races on the x-axis. The relevant variables I have are named FinancialAid and Race, and students are uniquely identified by the variable 'Randomid' (without the quotes). I hope I have given enough information!

    Thanks!

  • #2
    Hi. You might try this three-step process: 1) regress financial aid on race; 2) get the predicted values with "margins"; 3) create the bar graph using "marginsplot".

    Something like this:

    reg Financial Aid i.Race
    *(be sure to use the "i-dot" before "race" to indicate to Stata that "Race" is an unordered categorical variables)

    margins, over(Race)
    marginsplot, x(Race) recast(bar)

    I'm sure there's a way to do this with "twoway bar." Also, it helps if you post the code you've used.

    Best,
    David
    Web site:
    ​http://investigadores.cide.edu/crow/


    Las Américas y el Mundo:
    http://lasamericasyelmundo.cide.edu/

    ==========================================
    David Crow
    Associate Professor, División de Estudios Internacionales
    Centro de Investigación y Docencia Económicas (CIDE)
    ==========================================

    Comment


    • #3
      Will try that thanks, although it seem a bit involved for obtaining a simple summary figure of the proportion of people on financial aid.

      My code I've used at the moment is this:

      histogram FinancialAid, discrete percent by(Race)

      This code is almost what I want, except it shows the 0s by Race as well, and doesn't display the precise percentages of each - you sort have to "guesstimate" the proportion.

      Comment


      • #4
        I'm not entirely sure I understand what is wanted here but it sounds like

        Code:
        graph bar FinancialAid, over(Race)
        would be more or less it.

        Comment


        • #5
          Originally posted by Clyde Schechter View Post
          I'm not entirely sure I understand what is wanted here but it sounds like

          Code:
          graph bar FinancialAid, over(Race)
          would be more or less it.
          Yes, that works (see the first graph). However, I'd like to add the actual percentages above each column/bar. How would I go about doing that?

          Comment


          • #6
            This is documented. Use the blabel() option.

            You said your variable was 0-1 in which case its mean will be in that interval. Somehow you got a percent scale, so that is what you wanted.

            The title "percent of mean of FinancialAid" would be better as something like "percent on financial aid".

            You don't need a legend here. Your categories would fit well as axis labels.

            Showing the exact syntax you used is recommended.
            Last edited by Nick Cox; 28 Apr 2014, 02:14.

            Comment


            • #7
              A better way to display your data is to use horizontal bars. This allows the legend text to be abolished. The reader can read the identity of the category and the percentage in a single horizontal movement.

              I have not used different colours for different races, since all the bars show the same thing, and the colours are no longer needed to link individual bars to their labels.

              I have also used the vertical dimension of the chart to show the relative size of each category, rather than having them in an arbitrary order as you had.

              This was done with Nick Cox's -catplot- command. (I used frequency weights to indicate the size of each bar)

              . catplot rv_race [fw=percent]

              Comment


              • #8
                Originally posted by David Crow View Post
                Hi. You might try this three-step process: 1) regress financial aid on race; 2) get the predicted values with "margins"; 3) create the bar graph using "marginsplot".

                Something like this:

                reg Financial Aid i.Race
                *(be sure to use the "i-dot" before "race" to indicate to Stata that "Race" is an unordered categorical variables)

                margins, over(Race)
                marginsplot, x(Race) recast(bar)

                I'm sure there's a way to do this with "twoway bar." Also, it helps if you post the code you've used.

                Best, in m
                David
                I never knew that you could do this with the margins command! I just implemented this for a paper I am working on; is it possible to add the value labels to the bars using marginsplot? I couldn't figure out how to do it or find it in the options, and the blabel() option didn't work for me.

                Sincerely,

                Keith A. Preble
                University at Albany, SUNY
                [email protected]

                Comment


                • #9
                  I never knew that you could do this with the margins command!
                  -marginsplot- is a wrapper for -graph twoway- and it will take pretty much any -graph twoway- option you throw at it, so you can really customize the appearance of your graph with the full range of Stata's graph engine's capabilities.

                  Comment


                  • #10
                    Hi everyone,

                    I am new to stata. I would like to draw a bar graph that makes a distinction between 2 binary variables that are unrelated (or should I use another type of graph?)

                    I do research in bilateral trade between different countries and in particular how legal systems affect these trade volumes. I wonder hether there is more trade between two civil law legal system countries (dummy 'bothciv' = 0 or 1) or whether there is more trade when one of the trading countries is common law (regardless of whether they are both common law, one is enough, dummy 'com' = 0 or 1). So basically I research whether being both civil law generates more trade than having one of them being common law. I have all the necessary panel data in stata.


                    Thank you very much already.

                    Blanche Devos, European Master in Law and Economics
                    Last edited by Blanche Devos; 07 Aug 2019, 14:05.

                    Comment

                    Working...
                    X