Announcement

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

  • How to use If condition to restrict t test on only two groups with a categorical var that has 3 groups

    Hi Family,
    I have 1 categorical variable that has 3 grps( blue,yellow, green), I wanted check if the variance between only these two groups( blue and green) differs. So how do i use if condition to constraint the categorical variable to work with only the 2 groups out of the 3.

    Given that;
    the value label for blue=1 yellow=2 and green=3
    wait= Weight of individuals

    Below is the command I used but stata still generate an error.


    sdtest wait , by( grps ) if grps==1 & grps==3

    option if not allowedr(198);

    I need your help?

    Thank you.
    Amidu

  • #2
    Try
    Code:
    sdtest wait if inlist(grps, 1, 3), by(grps)

    Comment


    • #3
      Hi Joseph,
      Thank you soo much.
      It works so well.

      Comment


      • #4
        Code:
         if grps==1 | grps==3

        would be the if qualifier you need if you didn't use inlist().

        Comment


        • #5
          Ok thanks

          Comment


          • #6

            Dear Sir/Madam,
            I am currently working on a data set in a roster format containing timestamp, and I am facing an issue with the conversion of the timestamps to the required format. I have created two new variables, but unfortunately, I keep getting a "type mismatch" error while using the collapse command to sum the time differences according to the unique ID.
            To convert the timestamps, I used the following commands:
            • gen start_time_stata = clock(START_TIME_SECS, "YMDhms"): to convert the start timestamp
            • gen end_time_stata = clock(STOP_TIME_SECS, "YMDhms"): to convert the stop timestamp
            • gen time_diff = tdelta(end_time_stata, start_time_stata, "seconds"): to get the difference
            I would greatly appreciate your help in resolving this issue.
            I have attached the dataset for your reference.

            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input double(MRESPONSE_ID START_TIME_SECS STOP_TIME_SECS)
            1 1681182712 1681182762
            1 1681183070 1681183080
            1 1681183410 1681183423
            1 1681183467 1681183472
            2 1681184993 1681185138
            2 1681185312 1681185464
            2 1681185708 1681185926
            end



            Thank you very much in advance.


            Sham

            Comment


            • #7
              1 It would have been better to have started a new topic.

              2. clock() takes a string variable as its first argument. Those variables are not string.

              3. Use double-precision when working with date-time variables. (Actually, use double-precision for all floating-point variables and you won't have to worry about such things.)

              4. I didn't find the function tdelta() in Stata's help file for date-time functions.

              5. Try something along the lines of the following:

              .ÿ
              .ÿversionÿ17.0

              .ÿ
              .ÿclearÿ*

              .ÿ
              .ÿquietlyÿinputÿdouble(MRESPONSE_IDÿSTART_TIME_SECSÿSTOP_TIME_SECS)

              .ÿ
              .ÿ*
              .ÿ*ÿBeginÿhere
              .ÿ*
              .ÿformatÿ*TI*ÿ%tcHH:MM:SS.sss

              .ÿrenameÿ*,ÿlower

              .ÿgenerateÿdoubleÿtime_diffÿ=ÿclockdiff_frac(start_time_secs,ÿstop_time_secs,ÿ"second")

              .ÿformatÿtime_diffÿ%05.3f

              .ÿ
              .ÿlist,ÿnoobsÿabbreviate(20)ÿsepby(mresponse_id)

              ÿÿ+-------------------------------------------------------------+
              ÿÿ|ÿmresponse_idÿÿÿstart_time_secsÿÿÿstop_time_secsÿÿÿtime_diffÿ|
              ÿÿ|-------------------------------------------------------------|
              ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ10:59:42.712ÿÿÿÿÿ10:59:42.762ÿÿÿÿÿÿÿ0.050ÿ|
              ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ10:59:43.070ÿÿÿÿÿ10:59:43.080ÿÿÿÿÿÿÿ0.010ÿ|
              ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ10:59:43.410ÿÿÿÿÿ10:59:43.423ÿÿÿÿÿÿÿ0.013ÿ|
              ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ10:59:43.467ÿÿÿÿÿ10:59:43.472ÿÿÿÿÿÿÿ0.005ÿ|
              ÿÿ|-------------------------------------------------------------|
              ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿ10:59:44.993ÿÿÿÿÿ10:59:45.138ÿÿÿÿÿÿÿ0.145ÿ|
              ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿ10:59:45.312ÿÿÿÿÿ10:59:45.464ÿÿÿÿÿÿÿ0.152ÿ|
              ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿ10:59:45.708ÿÿÿÿÿ10:59:45.926ÿÿÿÿÿÿÿ0.218ÿ|
              ÿÿ+-------------------------------------------------------------+

              .ÿ
              .ÿexit

              endÿofÿdo-file


              .


              Comment


              • #8
                Dear Joseph and Team,,

                I would like to express my gratitude for your prompt advice. I must inform you that I do not possess the Version 17 of Stata, but instead I am utilizing Version 14. Although I have thoroughly reviewed your guide, I am unable to comprehend the instructions, possibly due to my utilization of the outdated version.

                I am grateful for your suggestion, however, I believe it may be a distinct topic and therefore, I plan to repost my inquiry. Please accept my apologies for any inconvenience this may have caused.

                Thank you once again for your assistance.

                Comment

                Working...
                X