Announcement

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

  • Finding p-values for the difference between the who dataset and the once that are missing.

    Dear all,

    I need to make a table like this with stata. But I do not know where to start. The person who supposed to help me with this just had a baby so I have nowhere to

    ​​​​go. I need to make a table like this 5.3 supplementary table (see below) . This is a table with all the excluded cases and included cases and a p-value for the difference is calculated per strata. I want to do this for my dataset, which is the same as this one but I excluded a few more and have a few less (120) and 536 included cases. I did make a variable that is called missings that has the once that are missing from this dataset =1 and not missing =0 (see missings). I want to find if the excluded cases and included cases differ. How do I do go about this? I thought I had it figured out, but it added all the missings to my dataset so all the sudden I had 756 observations. I'm completely lost by now. I did not attach a label to the missings yet. Should I do this or is simply 0 or 1 enough?
    This is my dataset.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double pid float missings byte gender float bmi_cat
    1001001 1 0 4
    1001002 0 0 3
    1001003 0 0 3
    1001004 0 0 3
    1001006 0 0 2
    1001007 0 0 3
    1001008 0 0 3
    1001010 0 0 2
    1001011 0 0 3
    1001012 0 0 4
    1001013 0 0 3
    1001014 0 0 3
    1001015 0 0 3
    1001016 0 0 3
    1001017 1 1 4
    1001018 0 1 3
    1001019 0 1 4
    1001020 0 1 3
    1001021 0 1 3
    1001022 0 1 3
    end
    label values gender sex
    label def sex 0 "Male", modify
    label def sex 1 "Female", modify
    label values bmi_cat bmil
    label def bmil 2 "Thinness", modify
    label def bmil 3 "Normal", modify
    label def bmil 4 "Overweight", modify
    ------------------ copy up to and including the previous line ------------------

    Listed 20 out of 536 observations


    Click image for larger version

Name:	Screenshot 2023-07-31 at 22.39.14.png
Views:	2
Size:	111.5 KB
ID:	1722401


    Thanks you so much for you valuable time.
    Best Anna
    Attached Files

  • #2
    Code:
    label define missings    0    "Included Cases"    1    "Excluded Cases"
    label values missings missings
    label var missing "Included vs Excluded"
    
    label var gender "Sex"
    label var bmi_cat "BMI Category"
    
    dtable i.gender i.bmi_cat, by(missings, test)
    In your example data, all of the variables you are working with are categorical, hence the i.'s in front of them all. If you have continuous variables as well, prefix those with c. instead.

    Comment


    • #3
      Thank you so much for your quick answer. However, I get the following error. I do have Stata17 though.
      dtable i.gender i.bmi_cat, by(missings, test)
      command dtable is unrecognized
      r(199);

      Comment


      • #4
        -dtable- was introduced in version 18. The Forum FAQ states that if you are not using the current version of Stata you are supposed to say which version you are using.

        -dtable- is a wrapper program for -table- and -collect- that offers many conveniences. I can get you part of the way to what you want in version 17:
        Code:
        label define missings    0    "Included Cases"    1    "Excluded Cases"
        label values missings missings
        label var missing "Included vs Excluded"
        
        label var gender "Sex"
        label var bmi_cat "BMI Category"
        
        table (var) (missings), statistic(freq) statistic(fvfreq gender bmi_cat) ///
            statistic(fvpercent gender bmi_cat) nformat(%2.1f fvpercent) ///
            sformat("(%s)" fvpercent) style(Table-1) nototals
        But this gives the percentages on separate lines, and it does not include the tests. There are ways to accomplish those goals as well, but they are beyond my skills with these commands. Perhaps somebody else following the thread can help.

        Comment

        Working...
        X