Announcement

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

  • Getting a table that shows sorted answers of two variables

    Hi!!!
    I would like to get a table with the percentage of people who answered three questions recorded in the three variables: Formalizacion, Estado_proceso, and Acuerdo, sorted by two other variables :Departamento and Municipio

    I know how to do it when it is just a question, like the following

    Formalizacion, sort: tabulate Departamento Municipio

    by Estado_Proceso, sort: tabulate Departamento Municipio

    but I do not know how to put two questions together int he same table, sorted by those variables

    Can anyone help me?



  • #2
    Silvana:
    no example=tentative reply:
    In addition, I doubt that your first code can give you back a single table:
    Code:
    use "C:\Program Files\Stata17\ado\base\a\auto.dta"
    . bysort mpg: tabulate foreign
    
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -> mpg = 12
    
     Car origin |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |          2      100.00      100.00
    ------------+-----------------------------------
          Total |          2      100.00
    
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -> mpg = 14
    
     Car origin |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |          5       83.33       83.33
        Foreign |          1       16.67      100.00
    ------------+-----------------------------------
          Total |          6      100.00
    
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -> mpg = 15
    
     Car origin |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |          2      100.00      100.00
    ------------+-----------------------------------
          Total |          2      100.00
    
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -> mpg = 16
    
     Car origin |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |          4      100.00      100.00
    ------------+-----------------------------------
          Total |          4      100.00
    
    <snip>
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      This would be legal, but I am not clear whether it is what you want:

      Code:
      bysort Formalizacion Estado_proceso Acuerdo:  tab Departamento Municipio
      Last edited by Nick Cox; 30 May 2023, 03:27.

      Comment


      • #4
        Dear Carlo, thanks for your reply

        Yesterday I tried what you have suggested,

        by Formalizacion, sort: tabulate Departamento Municipio

        ------------------------------------------------------------------------------------------------------------------------------------
        -> Formalizacion = Ninguno

        Departamen | Municipio
        to | A1 A2 B1 B2 B3 C1 D1 D2 | Total
        -----------+----------------------------------------------------------------------------------------+----------
        A | 65 176 0 0 0 0 0 0 | 241
        B | 0 0 76 51 329 0 0 0 | 456
        C | 0 0 0 0 0 37 0 0 | 37
        D | 0 0 0 0 0 0 103 159 | 262
        -----------+----------------------------------------------------------------------------------------+----------
        Total | 65 176 76 51 329 37 103 159 | 996


        ------------------------------------------------------------------------------------------------------------------------------------
        -> Formalizacion = Ns/Nr

        Departamen | Municipio
        to | A1 A2 B1 B2 B3 D1 D2 | Total
        -----------+-----------------------------------------------------------------------------+----------
        A | 1 1 0 0 0 0 0 | 2
        B | 0 0 2 1 14 0 0 | 17
        D | 0 0 0 0 0 2 2 | 4
        -----------+-----------------------------------------------------------------------------+----------
        Total | 1 1 2 1 14 2 2 | 23


        ------------------------------------------------------------------------------------------------------------------------------------
        -> Formalizacion = Otro

        Departamen | Municipio
        to | B1 B3 | Total
        -----------+----------------------+----------
        B | 1 6 | 7
        -----------+----------------------+----------
        Total | 1 6 | 7


        ------------------------------------------------------------------------------------------------------------------------------------
        -> Formalizacion = Restitución de tierras

        Departamen | Municipio
        to | B3 C1 D1 D2 | Total
        -----------+--------------------------------------------+----------
        B | 2 0 0 0 | 2
        C | 0 8 0 0 | 8
        D | 0 0 6 5 | 11
        -----------+--------------------------------------------+----------
        Total | 2 8 6 5 | 21


        ------------------------------------------------------------------------------------------------------------------------------------
        -> Formalizacion = Subsidio Integral de Tierras

        Departamen | Municipio
        to | A1 A2 B3 D1 | Total
        -----------+--------------------------------------------+----------
        A | 3 2 0 0 | 5
        B | 0 0 1 0 | 1
        D | 0 0 0 1 | 1
        -----------+--------------------------------------------+----------
        Total | 3 2 1 1 | 7


        ------------------------------------------------------------------------------------------------------------------------------------
        -> Formalizacion = Títulos Baldíos

        Departamen | Municipio
        to | A1 A2 B1 B2 B3 C1 D1 D2 | Total
        -----------+----------------------------------------------------------------------------------------+----------
        A | 1 3 0 0 0 0 0 0 | 4
        B | 0 0 6 2 30 0 0 0 | 38
        C | 0 0 0 0 0 3 0 0 | 3
        D | 0 0 0 0 0 0 2 3 | 5
        -----------+----------------------------------------------------------------------------------------+----------
        Total | 1 3 6 2 30 3 2 3 | 50



        but what I am trying to get is a table with the answers not only of Formlizacion, but with the answers of Estado_proceso Acuerdo.



        Dear Nick, thanks.

        I have also tried what you have suggested before, but I get this error

        bysort Formalizacion Estado_proceso Acuerdo: tab Departamento Municipio
        variable Estado_proceso not found

        Those three variables: Formalizacion Estado_proceso Acuerdo are string. I have tried changing them to numeric, but unsuccessfully

        destring Formalizacion, replace
        Formalizacion: contains nonnumeric characters; no replace

        I later tried this...but it's not what I was expecting

        destring Formalizacion, force replace
        Formalizacion: contains nonnumeric characters; replaced as byte
        (1104 missing values generated)


        Comment


        • #5
          In #1 you referred to Estado_proceso and also to Estado_Proceso. Now you are telling us that that you do have Estado_proceso but if so Stata should not complain. My guess is that you need to refer to Estado_Proceso in the command.

          In interpreting command syntax Stata is case-sensitive about variable names. So Estado_proceso and Estado_Proceso could be two different variable names and Stata won't translate either way.

          On the evidence you give you should not be trying destring here. destring is for variables with numeric content but misread as string, which is not what you have.

          Comment


          • #6
            It works! I did not take care of the capital letter.

            Comment

            Working...
            X