Announcement

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

  • Counting number of observation given certain value thresholds

    Good evening,

    I would like to create a graph, but need to know the number of observation in certain threshholds.

    I have a binary variable and another variable that has a monetary value attached to it.

    I woulld like to see the number of observation in the binary variable given the threshholds

    So if the binary value where 0, how many observations have a monetary value between 0, 0<-10000,10000-100000 and 1000000+

    Is there an easy way to count the observations in these 4 buckets, within the binary variable?

  • #2
    I'm confused by your describing a number of observations as being "in" a binary (0/1) variable, and also by what the relation is between the binary variable and the thresholds you describe.

    Given those uncertainties, my rather inexact attempt at advice would be to suggest you look at -help recode-, which you could use to create a categorized version of your monetary variable and then tabulate it.

    Comment


    • #3
      Sorry for not being clear.

      My data is sorted like this
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int id byte(_mi_m survey expectation gift_received)
      27 0 2 1 2
      27 1 2 1 2
      27 2 2 1 2
      27 3 2 1 2
      27 4 2 1 2
      27 5 2 1 2
      36 0 1 2 1
      36 0 2 2 2
      36 1 1 2 1
      36 1 2 2 2
      36 2 1 2 1
      36 2 2 2 2
      36 3 1 2 1
      36 3 2 2 2
      36 4 1 2 1
      36 4 2 2 2
      36 5 1 2 1
      36 5 2 2 2
      67 0 1 2 1
      67 0 2 2 1
      67 1 1 2 1
      67 1 2 2 1
      67 2 1 2 1
      67 2 2 2 1
      67 3 1 2 1
      67 3 2 2 1
      67 4 1 2 1
      67 4 2 2 1
      67 5 1 2 1
      67 5 2 2 1
      86 0 1 2 1
      86 0 2 2 2
      86 1 1 2 1
      86 1 2 2 2
      86 2 1 2 1
      86 2 2 2 2
      86 3 1 2 1
      86 3 2 2 2
      86 4 1 2 1
      86 4 2 2 2
      86 5 1 2 1
      86 5 2 2 2
      92 0 1 2 2
      92 0 2 2 2
      92 1 1 2 2
      92 1 2 2 2
      92 2 1 2 2
      92 2 2 2 2
      92 3 1 2 2
      92 3 2 2 2
      92 4 1 2 2
      92 4 2 2 2
      92 5 1 2 2
      92 5 2 2 2
      128 0 1 2 2
      128 0 2 2 2
      128 1 1 2 2
      128 1 2 2 2
      128 2 1 2 2
      128 2 2 2 2
      128 3 1 2 2
      128 3 2 2 2
      128 4 1 2 2
      128 4 2 2 2
      128 5 1 2 2
      128 5 2 2 2
      130 0 1 1 1
      130 1 1 1 1
      130 2 1 1 1
      130 3 1 1 1
      130 4 1 1 1
      130 5 1 1 1
      178 0 1 2 1
      178 1 1 2 1
      178 2 1 2 1
      178 3 1 2 1
      178 4 1 2 1
      178 5 1 2 1
      303 0 1 1 2
      303 1 1 1 2
      303 2 1 1 2
      303 3 1 1 2
      303 4 1 1 2
      303 5 1 1 2
      484 0 1 2 1
      484 0 2 2 2
      484 1 1 2 1
      484 1 2 2 2
      484 2 1 2 1
      484 2 2 2 2
      484 3 1 2 1
      484 3 2 2 2
      484 4 1 2 1
      484 4 2 2 2
      484 5 1 2 1
      484 5 2 2 2
      594 0 1 1 1
      594 0 2 2 2
      594 1 1 1 1
      594 1 2 2 2
      end
      And another variable, called "inheritance_received" includes the height of an inheritance received (sadly not home so can't post this variable, posting an old code from another topic), which is a value that can range between 0 and 10 million.

      The variable "expectation" is binary, 1 tells me they expect a future inheritance, 2 means they don't. I want to see how the variable "inheritance_received" is distributed.

      I want to group the variable in the before mentioned buckets and see the distribution within the binary variable, similar to the table I have uploaded. However, I think a graph would be better, and I am not able to get the table to work as I want. So I decided to just use a simple graph. Is this more clear now?
      Attached Files

      Comment


      • #4
        You can easily make groups with egen, cut(var). For example:
        Code:
        egen group = cut(inheritance_received), at(0, 10000, 100000, 1000000, 11000000) label
        Make sure the last value is higher than the maximum value in your variable. Then I guess you want something like:
        Code:
        graph bar (count), over(expectation) over(group)

        Comment

        Working...
        X