Announcement

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

  • creating proportions for time series graphs

    Dear all
    Can someone please help me to create a time-series graph. I want to display percentage/proportions per month of people died in my data over the last two years. I can simple crosstab and see what proportions per month something like this below,
    bysort year: tab month died,col row

    However, I believe I need to generate a separate variable which I can use in the time-series graph display my proportions, I am not able to do that, I have used below command
    by month, sort: egen pcdied = mean(100 * died)
    However, this seems to be generating different values compared to what I can see from my cross tabs and the difference is quite significant
    I need these percentages so I can do the following
    tsset time

    two (tsline pcdied month)

    Apologise for a daft question on this forum, I am not sharing the data here because I think its quite a simple function which I not able to do myself. However, if a data example is required I can share the dataex.



  • #2
    Code:
    bysort year: tab month died,col row
    
    
    by month, sort: egen pcdied = mean(100 * died)
    are not consistent commands. The second command doesn't mention year , for a start.

    I will guess that died is 1 or 0. That being so, consider this analogue.

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . gen himpg = mpg > 20
    
    . bysort himpg : tab rep78 foreign, row
    
    -------------------------------------------------------------------------------------------------------------
    -> himpg = 0
    
    +----------------+
    | Key            |
    |----------------|
    |   frequency    |
    | row percentage |
    +----------------+
    
        Repair |
        Record |       Car type
          1978 |  Domestic    Foreign |     Total
    -----------+----------------------+----------
             1 |         1          0 |         1
               |    100.00       0.00 |    100.00
    -----------+----------------------+----------
             2 |         5          0 |         5
               |    100.00       0.00 |    100.00
    -----------+----------------------+----------
             3 |        20          0 |        20
               |    100.00       0.00 |    100.00
    -----------+----------------------+----------
             4 |         6          0 |         6
               |    100.00       0.00 |    100.00
    -----------+----------------------+----------
             5 |         0          4 |         4
               |      0.00     100.00 |    100.00
    -----------+----------------------+----------
         Total |        32          4 |        36
               |     88.89      11.11 |    100.00
    
    -------------------------------------------------------------------------------------------------------------
    -> himpg = 1
    
    +----------------+
    | Key            |
    |----------------|
    |   frequency    |
    | row percentage |
    +----------------+
    
        Repair |
        Record |       Car type
          1978 |  Domestic    Foreign |     Total
    -----------+----------------------+----------
             1 |         1          0 |         1
               |    100.00       0.00 |    100.00
    -----------+----------------------+----------
             2 |         3          0 |         3
               |    100.00       0.00 |    100.00
    -----------+----------------------+----------
             3 |         7          3 |        10
               |     70.00      30.00 |    100.00
    -----------+----------------------+----------
             4 |         3          9 |        12
               |     25.00      75.00 |    100.00
    -----------+----------------------+----------
             5 |         2          5 |         7
               |     28.57      71.43 |    100.00
    -----------+----------------------+----------
         Total |        16         17 |        33
               |     48.48      51.52 |    100.00
    
    
    . egen wanted = mean(100 * foreign), by(himpg rep78)
    
    . format wanted %2.1f
    
    . tabdisp rep78 himpg , c(wanted)
    
    ------------------------
    Repair    |
    Record    |    himpg    
    1978      |     0      1
    ----------+-------------
            1 |   0.0    0.0
            2 |   0.0    0.0
            3 |   0.0   30.0
            4 |   0.0   75.0
            5 | 100.0   71.4
            . |  50.0    0.0
    ------------------------


    My guess is thus that you want:

    Code:
    by year month, sort: egen pcdied = mean(100 * died)

    Comment


    • #3
      Thank you Nick, you are helpful as always

      Comment

      Working...
      X