Announcement

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

  • Dropping subgroups with no observations (graphbar)

    I have a data structured as follows, and I am using the Stata graph bar guide here.

    ```
    dataex job_search_duration educ_institution gender

    ----------------------- copy starting from the next line -----------------------
    [CODE]
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float job_search_duration str103 educ_institution str8 gender
    1 "جامعة جازان" "ذكر"
    1 "جامعة جازان" "ذكر"
    1 "جامعة جازان" "ذكر"
    1 "جامعة جازان" "ذكر"
    1 "الكليات التقنية" "ذكر"
    0 "الكليات التقنية" "ذكر"
    1 "جامعة جازان" "ذكر"
    ```

    I am trying to exclude subgroups without any observations from appearing in the bar graph, so I ran the code below.
    I thought that by adding (drop if educ_institution==""), I would be able to drop such subgroups but the graph as you can

    ```
    preserve
    drop if job_search_duration<1
    drop if educ_institution==""
    graph hbar (mean) job_search_duration, over(educ_attainment, sort(1) descending) over(gender)
    restore
    ```
    Attached Files

  • #2
    Sorry, but I can't read this language (Arabic?), but I guess you need the nofill option.

    Note that if I am right the problem is not missing values -- observations in the dataset with missing values on one or more variables -- but absent values -- observations not in the dataset for category combinations that graph bar can't find.

    Comment


    • #3
      Thanks Nick, indeed this is Arabic. Your solution worked well!
      ```
      preserve
      drop if job_search_duration<1
      drop if educ_institution==""
      graph hbar (mean) job_search_duration, over(educ_attainment, sort(1) descending) over(gender) nofill
      restore
      ```

      Comment

      Working...
      X