Announcement

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

  • out of proportion

    Hi
    I'm building som code to summarize some survey proportions.
    And hence I use proportion to get it (I've ignored the svy prefix in the example below).:
    Code:
    sysuse auto, clear
    keep if rep78 >2
    proportion foreign, over( rep78)
    And then I get:
    Code:
    Proportion estimation               Number of obs    =      59
    
         Domestic: foreign = Domestic
          Foreign: foreign = Foreign
    
                3: rep78 = 3
                4: rep78 = 4
                5: rep78 = 5
    
    --------------------------------------------------------------
            Over | Proportion   Std. Err.     [95% Conf. Interval]
    -------------+------------------------------------------------
    Domestic     |
               3 |         .9   .0557086      .7227598    .9688186
               4 |         .5   .1212678      .2746861    .7253139
               5 |   .1818182   .1219673      .0412781    .5342249
    -------------+------------------------------------------------
    Foreign      |
               3 |         .1   .0557086      .0311814    .2772402
               4 |         .5   .1212678      .2746861    .7253139
               5 |   .8181818   .1219673      .4657751    .9587219
    --------------------------------------------------------------
    But what I actually want is only the proportions of foreign == Foreign in a way such that the values of rep78 can used to lookup the proper proportion.
    Is there a (simple) way of coding this (note that in my case foreign can have more than 2 values and I do only want to look at one of them)?
    Kind regards

    nhb

  • #2
    Niels Henrik - is this what you want?
    Code:
    proportion rep78 if foreign==1

    Comment


    • #3
      Hi Svend
      Thank you for your effort.
      But when I do that I get the wrong proportions:
      Code:
      . proportion rep78 if foreign==1
      
      Proportion estimation               Number of obs    =      21
      
      --------------------------------------------------------------
                   | Proportion   Std. Err.     [95% Conf. Interval]
      -------------+------------------------------------------------
      rep78        |
                 3 |   .1428571   .0782461      .0420994    .3872685
                 4 |   .4285714   .1106567      .2261428     .658104
                 5 |   .4285714   .1106567      .2261428     .658104
      --------------------------------------------------------------
      I want the line:
      Code:
                5 | .8181818 .1219673 .4657751 .9587219
      So it is more like the other way around:
      Code:
      . proportion foreign if rep78 == 5
      
      Proportion estimation               Number of obs    =      11
      
      --------------------------------------------------------------
                   | Proportion   Std. Err.     [95% Conf. Interval]
      -------------+------------------------------------------------
      foreign      |
          Domestic |   .1818182   .1219673      .0345259    .5799955
           Foreign |   .8181818   .1219673      .4200045    .9654741
      --------------------------------------------------------------
      And this is quite annoying, because that hasn't been working for me the whole day.
      But starting a new session apparently did the trick

      And then I can eg get what I want from
      Code:
      . mata select(st_matrix("r(table)")'[., (1,2,5,6)], st_matrixcolstripe("r(table)")[., 2] :== "Foreign")
                       1             2             3             4
          +---------------------------------------------------------+
        1 |  .8181818182   .1219673442   .4200045015   .9654741066  |
          +---------------------------------------------------------+
      Again thank you very much.
      Apparently the error mainly sat quite close to my screen
      Kind regards

      nhb

      Comment


      • #4
        For survey data, assuming you have sampling units, strata, ..., you might also consider:

        Code:
        . svy, subpop(if rep78==5): proportion foreign 
        (running proportion on estimation sample)
        
        Survey: Proportion estimation
        
        Number of strata =       1          Number of obs    =      64
        Number of PSUs   =      64          Population size  =      64
                                            Subpop. no. obs  =      11
                                            Subpop. size     =      11
                                            Design df        =      63
        
        --------------------------------------------------------------
                     |             Linearized
                     | Proportion   Std. Err.     [95% Conf. Interval]
        -------------+------------------------------------------------
        foreign      |
            Domestic |   .1818182   .1172106      .0439986    .5176044
             Foreign |   .8181818   .1172106      .4823956    .9560014
        --------------------------------------------------------------

        Comment


        • #5
          Hi Jeff
          Thank you very much.
          I'll look into it.
          Kind regards

          nhb

          Comment

          Working...
          X