Announcement

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

  • define command and dtable

    Hello,

    I found the below coding as an example on STATA website and I am trying to edit it to fit for the data analysis I need. Stata does not recognize the define command, what am I missing?

    Thanks!



    dtable, by(heartatk, tests) svy
    define(meansd = mean sd, delimiter(" ± "))
    define(myiqr = p25 p75, delimiter("-"))
    continuous(age, stat(meansd) test(none))
    continuous(bmi, stat(meansd))
    continuous(bpsystol tcresult, stat(median myiqr))
    nformat(%6.0f p25 p75 median) sformat("(%s)" myiqr) nformat(%6.1f mean sd) sformat("%s" sd)





    "command define is unrecognized" is the error it gives.
    Last edited by Betty Wolde; 30 Jul 2024, 10:20.

  • #2
    There is no -define- command. There is a -define()- option to the -dtable- command. The reason that Stata thinks you are talking about a separate command is because you have spread the code across multiple lines without telling Stata that you want to do that. Stata, by default, assumes each command begins and ends on a single line. If you have a long command that you want to continue across multiple lines, you have to put a continuation marker, -///-, at the end of all but the last line:
    Code:
    dtable, by(heartatk, tests) svy ///
    define(meansd = mean sd, delimiter(" ± ")) ///
    define(myiqr = p25 p75, delimiter("-")) ///
    continuous(age, stat(meansd) test(none)) ///
    continuous(bmi, stat(meansd)) ///
    continuous(bpsystol tcresult, stat(median myiqr)) ///
    nformat(%6.0f p25 p75 median) sformat("(%s)" myiqr) nformat(%6.1f mean sd) sformat("%s" sd)
    There are other ways to tell Stata to continue the same command on the following line, but this is the simplest, and, I think the most commonly used and least problematic.

    Added: Not germane to your question, but using - as the delimiter for a range, as in myiqr, is not a good idea because it creates an awkward looking result if negative numberes are involved. It's OK if you are sure there will never be negative numbers. That certainly will be true for systolic blood pressure. I'm not sure what tcresult is--if it's total cholesterol, then that's fine, too. But if it's something that could be negative, you'd be better off using something else. I generally use commas to delimit my iqr's and confidence intervals, although I suppose that would be very confusing if I were writing for an audience that primarily uses commas as decimal points.
    Last edited by Clyde Schechter; 30 Jul 2024, 10:30.

    Comment


    • #3
      Thank you! That was very helpful.

      Comment


      • #4
        I am trying to have the results in different columns for means and myiqr, would appreciate suggestions as variations of the below code did not result in the format I am trying to create.

        dtable, by(hepc, tests) define(meansd = mean sd, delimiter(" ± ")) ///
        define(myiqr = p25 p75, delimiter(",")) ///
        continuous(age, stat(meansd) test(none)) ///
        continuous(bmi, stat(meansd)) ///
        continuous(il6 , stat(median myiqr)) ///
        nformat(%6.1f mean sd) sformat("%s" sd) ///
        column(by (hide) total(All) test(P-value)) ///
        title(Table 1. IM Hep C Serostatus)

        Comment


        • #5
          See https://www.stata.com/support/faqs/r...ve-statistics/.

          Comment


          • #6
            Will give that a try and see. Thank you!

            Comment

            Working...
            X