Announcement

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

  • Regression problem

    Hello to all,
    I am currently writing my final paper. During one of my regressions I would like to split a variable to have a regression on each of the characteristics of this variable but I don't know which code to use.
    I would like to have a result like the variable "Type" below.
    Thanks in advance to all.

    Click image for larger version

Name:	Image1.png
Views:	1
Size:	200.6 KB
ID:	1676578

  • #2
    It sounds like you probably want to use factor variable notation.
    This would probably look something like this, where contvar1 & contvar2 are continuous and catvar1 is categorical.
    Code:
    reg outcome contvar1 contvar2 i.catvar1

    For more information:
    Code:
     help factor_variable

    Comment


    • #3
      Matteo:
      as an aside to Sarah's helpful advice, please note that the would-be -i.whatever- predictor seems to play the only relevant role in your regression. Therefore, I would check your model specification.
      Eventually, please do not snip the top of your Stata outcome table, as it can be informative for interested listers. Thanks.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Thank you for your answer.
        Unfortunately I don't have the top of the regression.
        I have a "category" variable and I would like to have a regression for each category as for the "type" variable above. But I can only get one line for this variable as below.
        Click image for larger version

Name:	Capture d’écran (26).png
Views:	1
Size:	217.8 KB
ID:	1676647

        Comment


        • #5
          Matteo:
          what if you prefix your previous code with:
          Code:
          bysort <yourcategoricalcariable>: <yourcode>
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            I don't know if my variables have been defined as "cotegorical". How can I see this and transform it if necessary?
            thanks

            Comment


            • #7
              Matteo:
              ignoring the type of the variables included in our datasets is not the best place to start (and, at the top of that, if we ignore the features of the dataset we're working on, how could others help us out?).
              That said, I meant something like the silly following toy-example:
              Code:
              . use https://www.stata-press.com/data/r17/cancer.dta
              (Patient survival in drug trial)
              
              
              . bysort drug: streg age, distribution(loglog)
              
              ------------------------------------------------------------------------------------------------------------------------------------------
              -> drug = Placebo
              
                      Failure _d: died
                Analysis time _t: studytime
              
              Fitting constant-only model:
              Iteration 0:   log likelihood = -30.747498  
              Iteration 1:   log likelihood = -28.980579  
              Iteration 2:   log likelihood = -26.303299  
              Iteration 3:   log likelihood =  -26.27276  
              Iteration 4:   log likelihood = -26.272715  
              Iteration 5:   log likelihood = -26.272715  
              
              Fitting full model:
              Iteration 0:   log likelihood = -26.272715  
              Iteration 1:   log likelihood = -24.549211  
              Iteration 2:   log likelihood = -22.902124  
              Iteration 3:   log likelihood = -22.883908  
              Iteration 4:   log likelihood = -22.883889  
              Iteration 5:   log likelihood = -22.883889  
              
              Loglogistic AFT regression
              
              No. of subjects =  20                                   Number of obs =     20
              No. of failures =  19
              Time at risk    = 180
                                                                      LR chi2(1)    =   6.78
              Log likelihood = -22.883889                             Prob > chi2   = 0.0092
              
              ------------------------------------------------------------------------------
                        _t | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                       age |  -.0863041   .0314849    -2.74   0.006    -.1480134   -.0245948
                     _cons |   6.775122   1.742047     3.89   0.000     3.360772    10.18947
              -------------+----------------------------------------------------------------
                  /lngamma |  -.8228366   .1912755    -4.30   0.000     -1.19773   -.4479434
              -------------+----------------------------------------------------------------
                     gamma |   .4391841   .0840052                      .3018788    .6389408
              ------------------------------------------------------------------------------
              
              ------------------------------------------------------------------------------------------------------------------------------------------
              -> drug = Other
              
                      Failure _d: died
                Analysis time _t: studytime
              
              Fitting constant-only model:
              Iteration 0:   log likelihood = -13.392784  (not concave)
              Iteration 1:   log likelihood = -11.336688  
              Iteration 2:   log likelihood = -10.190155  
              Iteration 3:   log likelihood = -10.004136  
              Iteration 4:   log likelihood = -9.9989956  
              Iteration 5:   log likelihood = -9.9989938  
              Iteration 6:   log likelihood = -9.9989938  
              
              Fitting full model:
              Iteration 0:   log likelihood = -9.9989938  
              Iteration 1:   log likelihood = -7.7701123  (backed up)
              Iteration 2:   log likelihood = -7.1998638  
              Iteration 3:   log likelihood = -7.1926194  
              Iteration 4:   log likelihood =  -7.192616  
              Iteration 5:   log likelihood =  -7.192616  
              
              Loglogistic AFT regression
              
              No. of subjects =  14                                   Number of obs =     14
              No. of failures =   6
              Time at risk    = 209
                                                                      LR chi2(1)    =   5.61
              Log likelihood = -7.192616                              Prob > chi2   = 0.0178
              
              ------------------------------------------------------------------------------
                        _t | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                       age |  -.0637127    .027747    -2.30   0.022    -.1180959   -.0093296
                     _cons |   6.619495   1.637598     4.04   0.000     3.409863    9.829127
              -------------+----------------------------------------------------------------
                  /lngamma |  -1.245188    .312067    -3.99   0.000    -1.856828   -.6335475
              -------------+----------------------------------------------------------------
                     gamma |   .2878869     .08984                      .1561672    .5307058
              ------------------------------------------------------------------------------
              
              ------------------------------------------------------------------------------------------------------------------------------------------
              -> drug = NA
              
                      Failure _d: died
                Analysis time _t: studytime
              
              Fitting constant-only model:
              Iteration 0:   log likelihood = -13.821488  
              Iteration 1:   log likelihood = -12.400049  
              Iteration 2:   log likelihood = -12.086157  
              Iteration 3:   log likelihood = -12.034182  
              Iteration 4:   log likelihood = -12.034087  
              Iteration 5:   log likelihood = -12.034087  
              
              Fitting full model:
              Iteration 0:   log likelihood = -12.034087  
              Iteration 1:   log likelihood = -11.704407  
              Iteration 2:   log likelihood = -11.658403  
              Iteration 3:   log likelihood = -11.658237  
              Iteration 4:   log likelihood = -11.658237  
              
              Loglogistic AFT regression
              
              No. of subjects =  14                                   Number of obs =     14
              No. of failures =   6
              Time at risk    = 355
                                                                      LR chi2(1)    =   0.75
              Log likelihood = -11.658237                             Prob > chi2   = 0.3859
              
              ------------------------------------------------------------------------------
                        _t | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                       age |  -.0492703   .0615586    -0.80   0.423     -.169923    .0713823
                     _cons |   6.314712   3.472244     1.82   0.069    -.4907606    13.12018
              -------------+----------------------------------------------------------------
                  /lngamma |  -.7831154   .3639645    -2.15   0.031    -1.496473    -.069758
              -------------+----------------------------------------------------------------
                     gamma |   .4569801   .1663245                      .2239186    .9326195
              ------------------------------------------------------------------------------
              
              .
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment

              Working...
              X