Announcement

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

  • #16
    Originally posted by Nick Cox View Post
    These are different variables. But zeros in the table would be problematic. You have a choice. You can either pursue #10 in which case #11 and #13 still apply; or pursue #14 in which case we need to see (1) the graph code you tried and (2) the results of


    Code:
    contract , zero
    dataex
    with the two variables in #14. So if the variables were a b (they aren't) you need to go

    Code:
    contract a b, zero
    dataex
    See also https://www.statalist.org/forums/help#stata for how to present data examples here.
    Thanks for your patience with me!
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(Q2061A Q609) int _freq
    1 1 3327
    1 2 4949
    1 3 1144
    1 98 124
    1 99 41
    1 . 172
    2 1 1310
    2 2 2131
    2 3 444
    2 98 47
    2 99 22
    2 . 574
    3 1 172
    3 2 275
    3 3 78
    3 98 7
    3 99 2
    3 . 10
    6 1 417
    6 2 649
    6 3 154
    6 98 12
    6 99 1
    6 . 92
    7 1 721
    7 2 1128
    7 3 206
    7 98 18
    7 99 8
    7 . 70
    8 1 280
    8 2 357
    8 3 99
    8 98 11
    8 99 5
    8 . 13
    11 1 666
    11 2 705
    11 3 254
    11 98 18
    11 99 4
    11 . 9
    12 1 911
    12 2 1197
    12 3 255
    12 98 24
    12 99 5
    12 . 270
    13 1 446
    13 2 567
    13 3 123
    13 98 16
    13 99 1
    13 . 12
    14 1 317
    14 2 458
    14 3 162
    14 98 13
    14 99 6
    14 . 10
    15 1 261
    15 2 385
    15 3 118
    15 98 40
    15 99 8
    15 . 58
    98 1 103
    98 2 96
    98 3 39
    98 98 14
    98 99 0
    98 . 61
    99 1 22
    99 2 9
    99 3 5
    99 98 0
    99 99 0
    99 . 41
    . 1 0
    . 2 1
    . 3 0
    . 98 0
    . 99 0
    . . 0
    end
    label values Q2061A Q2061A
    label def Q2061A 1 "economic situation", modify
    label def Q2061A 2 "financial and administrative corruption", modify
    label def Q2061A 3 "democracy and representation/governance", modify
    label def Q2061A 6 "internal stability and security", modify
    label def Q2061A 7 "foreign interference", modify
    label def Q2061A 8 "religious extremism", modify
    label def Q2061A 11 "fighting terrorism", modify
    label def Q2061A 12 "public services", modify
    label def Q2061A 13 "security", modify
    label def Q2061A 14 "political/party issues", modify
    label def Q2061A 15 "other", modify
    label def Q2061A 98 "don't know", modify
    label def Q2061A 99 "refused", modify
    label values Q609 Q609
    label def Q609 1 "religious", modify
    label def Q609 2 "somewhat religious", modify
    label def Q609 3 "not religious", modify
    label def Q609 98 "don't know", modify
    label def Q609 99 "refused", modify

    And here's the code:


    . bysort Q2061A Q609: gen freq = _N if Q609 == 1
    (70 missing values generated)

    . by Q2061A (Q609) : replace freq = -freq[_N]
    (14 real changes made, 14 to missing)


    . egen group = group(freq Q2061A)
    (84 missing values generated)


    . labmask group, values(Q2061A) decode
    no observations


    When I used this command: by Q2061A (Q609) : replace freq = -freq[_N] with a binomial variable like gender, things worked smoothly, but now I end up replacing the variables with missings.

    Comment


    • #17
      Thanks for the data example, but for anyone watching

      (1) the data example is what you would see if you ran contract Q2061A Q609, zero

      (2) the code following is for a differentset-up.

      As explained in https://www.statalist.org/forums/help#stata data examples should be presented as CODE using the delimiters provided by dataex or as provided by the # button in the forum software.

      This code takes (1) and orders the rows of the plot according to the frequencies of people answering 1 to Q609 (highest value at the top).

      Code:
      clear
      input double(Q2061A Q609) int _freq
      1 1 3327
      1 2 4949
      1 3 1144
      1 98 124
      1 99 41
      1 . 172
      2 1 1310
      2 2 2131
      2 3 444
      2 98 47
      2 99 22
      2 . 574
      3 1 172
      3 2 275
      3 3 78
      3 98 7
      3 99 2
      3 . 10
      6 1 417
      6 2 649
      6 3 154
      6 98 12
      6 99 1
      6 . 92
      7 1 721
      7 2 1128
      7 3 206
      7 98 18
      7 99 8
      7 . 70
      8 1 280
      8 2 357
      8 3 99
      8 98 11
      8 99 5
      8 . 13
      11 1 666
      11 2 705
      11 3 254
      11 98 18
      11 99 4
      11 . 9
      12 1 911
      12 2 1197
      12 3 255
      12 98 24
      12 99 5
      12 . 270
      13 1 446
      13 2 567
      13 3 123
      13 98 16
      13 99 1
      13 . 12
      14 1 317
      14 2 458
      14 3 162
      14 98 13
      14 99 6
      14 . 10
      15 1 261
      15 2 385
      15 3 118
      15 98 40
      15 99 8
      15 . 58
      98 1 103
      98 2 96
      98 3 39
      98 98 14
      98 99 0
      98 . 61
      99 1 22
      99 2 9
      99 3 5
      99 98 0
      99 99 0
      99 . 41
      . 1 0
      . 2 1
      . 3 0
      . 98 0
      . 99 0
      . . 0
      end
      label values Q2061A Q2061A
      label def Q2061A 1 "economic situation", modify
      label def Q2061A 2 "financial and administrative corruption", modify
      label def Q2061A 3 "democracy and representation/governance", modify
      label def Q2061A 6 "internal stability and security", modify
      label def Q2061A 7 "foreign interference", modify
      label def Q2061A 8 "religious extremism", modify
      label def Q2061A 11 "fighting terrorism", modify
      label def Q2061A 12 "public services", modify
      label def Q2061A 13 "security", modify
      label def Q2061A 14 "political/party issues", modify
      label def Q2061A 15 "other", modify
      label def Q2061A 98 "don't know", modify
      label def Q2061A 99 "refused", modify
      label values Q609 Q609
      label def Q609 1 "religious", modify
      label def Q609 2 "somewhat", modify
      label def Q609 3 "not", modify
      label def Q609 98 "don't know", modify
      label def Q609 99 "refused", modify
      
      * bysort Q2061A Q609: gen freq = _N if Q609 == 1
      
      * by Q2061A (Q609) : replace freq = -freq[_N]
      * egen group = group(freq Q2061A)
      * labmask group, values(Q2061A) decode
      
      set scheme s1color 
      
      egen tosort = total(cond(Q609 == 1, -_freq, .)) , by(Q2061A) 
      egen order = group(tosort Q2061A) 
      labmask order, values(Q2061A) decode 
      
      tabplot  order Q609 [fw=_freq], yla(, labsize(small)) bfcolor(none) xla(, labsize(small)) ytitle("") xtitle("") subtitle("") showval(offset(0.2))

      Comment


      • #18
        #17 can now be reproduced more briefly making use of myaxis from SSC, which will be announced separately.


        Code:
        clear
        input double(Q2061A Q609) int _freq
        1 1 3327
        1 2 4949
        1 3 1144
        1 98 124
        1 99 41
        1 . 172
        2 1 1310
        2 2 2131
        2 3 444
        2 98 47
        2 99 22
        2 . 574
        3 1 172
        3 2 275
        3 3 78
        3 98 7
        3 99 2
        3 . 10
        6 1 417
        6 2 649
        6 3 154
        6 98 12
        6 99 1
        6 . 92
        7 1 721
        7 2 1128
        7 3 206
        7 98 18
        7 99 8
        7 . 70
        8 1 280
        8 2 357
        8 3 99
        8 98 11
        8 99 5
        8 . 13
        11 1 666
        11 2 705
        11 3 254
        11 98 18
        11 99 4
        11 . 9
        12 1 911
        12 2 1197
        12 3 255
        12 98 24
        12 99 5
        12 . 270
        13 1 446
        13 2 567
        13 3 123
        13 98 16
        13 99 1
        13 . 12
        14 1 317
        14 2 458
        14 3 162
        14 98 13
        14 99 6
        14 . 10
        15 1 261
        15 2 385
        15 3 118
        15 98 40
        15 99 8
        15 . 58
        98 1 103
        98 2 96
        98 3 39
        98 98 14
        98 99 0
        98 . 61
        99 1 22
        99 2 9
        99 3 5
        99 98 0
        99 99 0
        99 . 41
        . 1 0
        . 2 1
        . 3 0
        . 98 0
        . 99 0
        . . 0
        end
        label values Q2061A Q2061A
        label def Q2061A 1 "economic situation", modify
        label def Q2061A 2 "financial and administrative corruption", modify
        label def Q2061A 3 "democracy and representation/governance", modify
        label def Q2061A 6 "internal stability and security", modify
        label def Q2061A 7 "foreign interference", modify
        label def Q2061A 8 "religious extremism", modify
        label def Q2061A 11 "fighting terrorism", modify
        label def Q2061A 12 "public services", modify
        label def Q2061A 13 "security", modify
        label def Q2061A 14 "political/party issues", modify
        label def Q2061A 15 "other", modify
        label def Q2061A 98 "don't know", modify
        label def Q2061A 99 "refused", modify
        label values Q609 Q609
        label def Q609 1 "religious", modify
        label def Q609 2 "somewhat", modify
        label def Q609 3 "not", modify
        label def Q609 98 "don't know", modify
        label def Q609 99 "refused", modify
        
        set scheme s1color
        
        myaxis order=Q2061A , sort(mean _freq) subset(Q609==1) descending
        tabplot  order Q609 [fw=_freq], yla(, labsize(small)) bfcolor(none) xla(, labsize(small)) ytitle("") xtitle("") subtitle("") showval(offset(0.2))
        Last edited by Nick Cox; 19 Mar 2021, 08:59.

        Comment

        Working...
        X