Announcement

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

  • Why I am Getting

    I am using Scott Long's user created command mtable which is from his Spost13 package.

    I have generated a variable that I am trying to calculate the margins for a variable I have created (HispanicUnhealthyLifestyle) against my outcome variable (clinicaldepression) but it says there are no observations.

    gen HispanicUnhealthyLifestyle = race == 2 & numcigs_r == 30 & exercise == 0

    sum clinicaldepression if HispanicUnhealthyLifestyle

    Variable | Obs Mean Std. Dev. Min Max
    -------------+---------------------------------------------------------
    clinicalde~n | 0



    qui mtable if HispanicUnhealthyLifestyle, rowname(HispanicUnhealthyLifestyle)
    > ///
    > atmeans ci below
    no observations
    r(2000);


    I am providing a data example below.



    dataex HispanicUnhealthyLifestyle

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float HispanicUnhealthyLifestyle
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 420 observations
    Use the count() option to list more

    My question is the following: How do I locate at which values there would be observations for my variable Hispanic?

  • #2
    I would start by using -summarize- to analyze subsets of the data:
    Code:
    sum numcigs_r if race==2 & exercise==0 
    sum numcigs_r if race==2 & exercise==0 , detail
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Roman:
      you may want to try something along the following lines:
      Code:
      sysuse auto.dta
      bysort foreign: list make if foreign==1 & _n==1
      Kind regards,
      Carlo
      (StataNow 18.5)

      Comment


      • #4
        Thank you Carole and Carlo for responding.

        sum numcigs_r if race==2 & exercise==0

        Variable | Obs Mean Std. Dev. Min Max
        -------------+---------------------------------------------------------
        numcigs_r | 5 2.2 1.788854 1 5

        . sum numcigs_r if race==2 & exercise==0 , detail

        numcigs_r
        -------------------------------------------------------------
        Percentiles Smallest
        1% 1 1
        5% 1 1
        10% 1 1 Obs 5
        25% 1 3 Sum of Wgt. 5

        50% 1 Mean 2.2
        Largest Std. Dev. 1.788854
        75% 3 1
        90% 5 1 Variance 3.2
        95% 5 3 Skewness .84375
        99% 5 5 Kurtosis 2.078125


        It appears that there are 5 observations at the specifications I am interested. Why would it then report 0 observations against the outcome variable (clinicialdepression) in post 1?

        Comment


        • #5
          I'm seeing that the maximum value for numcigs_r==5. You specified numcigs_r==30 in #1. There are no observations where numcigs_r==30.
          Stata/MP 14.1 (64-bit x86-64)
          Revision 19 May 2016
          Win 8.1

          Comment


          • #6
            Hi, Carole:


            . sum numcigs_r if race==1 & exercise==1

            Variable | Obs Mean Std. Dev. Min Max
            -------------+---------------------------------------------------------
            numcigs_r | 14 3.928571 5.210408 0 21

            . sum numcigs_r if race==1 & exercise==1 , detail

            numcigs_r
            -------------------------------------------------------------
            Percentiles Smallest
            1% 0 0
            5% 0 1
            10% 1 1 Obs 14
            25% 1 1 Sum of Wgt. 14

            50% 2 Mean 3.928571
            Largest Std. Dev. 5.210408
            75% 5 5
            90% 5 5 Variance 27.14835
            95% 21 5 Skewness 2.717046
            99% 21 21 Kurtosis 9.604744

            I want to know which value I need for my race == 1 value (black) when exercise == 1. I put 4 for numcig_r but that returned no observations.



            . sum numcigs_r if race==1 & exercise==1

            Variable | Obs Mean Std. Dev. Min Max
            -------------+---------------------------------------------------------
            numcigs_r | 14 3.928571 5.210408 0 21

            sum clinicaldepression if BlackModerateLifestyle

            Variable | Obs Mean Std. Dev. Min Max
            -------------+---------------------------------------------------------
            clinicalde~n | 0

            . mtable if BlackModerateLifestyle, rowname(BlackModerateLifestyle) ///
            > atmeans ci below
            no observations
            r(2000);

            Comment


            • #7
              Apparently there are no obs for those specific values. Since I don't know the goal for your study, I'll just suggest you use the median or 25th/75th percentile values since you know those exist. Alternatively, you can list all available values in the data for those groups:
              Code:
              tab numcigs_r if race==1 & exercise==1, nolab
              Stata/MP 14.1 (64-bit x86-64)
              Revision 19 May 2016
              Win 8.1

              Comment


              • #8
                Thank you!

                Comment

                Working...
                X