Announcement

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

  • Crosstab of two variables, specifying a single value for each variable

    Hello Statalist,

    I'm sure this is a very simply question for most of you.

    I have two variables, Q43 and Q44.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte Q43
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    end
    label values Q43 Q43
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte Q44
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    end
    label values Q44 Q44
    Just in case the data example should lead you to believe so, both variables are not just filled with missings, as you can see here

    Code:
    codebook Q43
    
    ----------------------------------------------------------------------------------------------------------------
    Q43                             In your opinion, what is the IDEAL situation for a young child in a two-parent h
    ----------------------------------------------------------------------------------------------------------------
    
                      type:  numeric (byte)
                     label:  Q43
    
                     range:  [1,99]                       units:  1
             unique values:  4                        missing .:  5,934/7,963
    
                tabulation:  Freq.   Numeric  Label
                               341         1  Both parents working full time
                               718         2  One parent working full time and
                                              one parent working part time
                               948         3  One parent working full time and
                                              one parent not working outside
                                              the home
                                22        99  Refused
                             5,934         .
    Code:
    codebook Q44
    
    ----------------------------------------------------------------------------------------------------------------
    Q44                             Which parent do you think should [work part time /not work outside the home] in 
    ----------------------------------------------------------------------------------------------------------------
    
                      type:  numeric (byte)
                     label:  Q44
    
                     range:  [1,99]                       units:  1
             unique values:  4                        missing .:  6,297/7,963
    
                tabulation:  Freq.   Numeric  Label
                                86         1  The father
                               637         2  The mother
                               937         3  It doesn't matter which parent
                                              {#Q44_Insert2}
                                 6        99  Refused
                             6,297         .
    Now, I simply would like to have a table of those observations, where Q43=1 and Q44=.

    For some reason, none of the commands I know with which I would like to do this are working, specifically tab, list, or count:

    Code:
    . tab Q43==1 if Q44==.
    == invalid name
    r(198);
    
    . list Q43==1 if Q44==.
    == invalid name
    r(198);
    
    . count Q43==1 if Q44==.
    varlist not allowed
    r(101);
    I'm also not getting wiser through the help function for any of these commands.

    Grateful for any help in overcoming this roadblock.

  • #2
    Here's an example:

    Code:
    . input Q1 Q2
    
                Q1         Q2
      1. . 2
      2. 1 3
      3. 3 2
      4. 1 .
      5. 1 .
      6. 1 .
      7. 1 .
      8. 1 .
      9. 1 .
     10. 1 .
     11. end
    
    . tab1 Q1 Q2 if Q1 ==1 & Q2 ==., missing
    
    -> tabulation of Q1 if Q1 ==1 & Q2 ==. 
    
             Q1 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |          7      100.00      100.00
    ------------+-----------------------------------
          Total |          7      100.00
    
    -> tabulation of Q2 if Q1 ==1 & Q2 ==. 
    
             Q2 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              . |          7      100.00      100.00
    ------------+-----------------------------------
          Total |          7      100.00
    
    . tab2 Q1 Q2 if Q1 ==1 & Q2 ==., missing
    
    -> tabulation of Q1 by Q2 if Q1 ==1 & Q2 ==. 
    
               |     Q2
            Q1 |         . |     Total
    -----------+-----------+----------
             1 |         7 |         7 
    -----------+-----------+----------
         Total |         7 |         7 
    
      
    .
    Best regards,

    Marcos

    Comment


    • #3
      Marcos Almeida Thank you so much! Not only does this work, but I get it now.

      Comment


      • #4
        Why not just

        Code:
        tab Q1 Q2, missing
        ?

        Comment


        • #5
          I wouldn't want to tab all missings for both variables, as each variable has 5000+ missings. Or am I misreading the syntax again?

          Comment


          • #6
            You should try it! If missing means just system missing, you have at most one extra row and one extra column in the table.

            Comment

            Working...
            X