Announcement

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

  • Using lfit with log(x)

    Hi, my equation of my regression is : Y=B0 + B1*log(x)
    I would like to get a graph with this equation and the standard error.
    I found lfitci for linear and qfitci for quadratic but is it possible to do it with log(X)? And i want to keep the X axis not in log

    When i type Help lfitci i find this:
    "Do not use twoway lfitci when specifying the axis scale options yscale(log) or xscale(log) to create log scales.
    The result may look pretty, but if you think about it, it is not what you want. The prediction line is not straight because the regression estimated for the prediction was for mpg on weight, not for mpg on log(weight)."
    But what can i do?
    Thanks you
    Last edited by Raph Selenite; 19 Jan 2021, 03:38.

  • #2
    If you want to see my data are like that :
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int x float y
     0        0
     1 .1548862
     2 .2379118
     3 .2892319
     4 .3260388
     5 .3644649
     6 .3922639
     7 .4186986
     8 .4383615
     9 .4494756
    10 .4628764
    11 .4641879
    12 .4793445
    13 .4853997
    14 .4953207
    15 .5005289
    16 .5024089
    17 .5074151
    18 .5121251
    19 .5120746
    20 .5173022
     0        0
     1  .102379
     2 .1582204
     3 .2026656
     4 .2365586
     5 .2641259
     6 .2966898
     7 .3183681
     8 .3429714
     9 .3606873
    10 .3844151
    11  .391101
    12  .410658
    13 .4296211
    14 .4392041
    15 .4572004
    16 .4701428
    17 .4829948
    18 .4969723
    19 .5088255
    20 .5191833
    end

    And i would like to get the first graph graph but with CI (like the second but with Y=B0+B1*ln(X)) :

    Code:
    gen ln_x=ln(x)
    reg y ln_x
    gen reg=_b[_cons]+_b[ln_x]*ln_x
    twoway (scatter y x, sort) (line reg x, sort)
    graph twoway (lfitci y x) (scatter y x)

    I don't know if it's possible

    Thanks you !

    Comment


    • #3
      Is this what you want?
      Code:
      gen ln_x=ln(x)
      reg y ln_x
      predict yhat
      predict s,stdf
      gen low=yhat-1.96*s
      gen high=yhat+1.96*s
      twoway rarea low hi x, sort color(gs14)  ///
             ||scatter  y x ,sort ///
             || line yhat x,sort  ///
             ,legend(order(1 "CI" 2 3) row(1))
      Then you can get:
      By the way,I don't think it is a good idea to plot like this.Because if change ln_x to x,the confidence interval may also change.In the graph which I plot,the confidence interval do not change.
      Attached Files
      Best regards.

      Raymond Zhang
      Stata 17.0,MP

      Comment


      • #4
        Hi Raph ,have you solved this problem?
        Best regards.

        Raymond Zhang
        Stata 17.0,MP

        Comment


        • #5
          Hi ! Thank you ! This morning I found the same type of formula but with "predict s, stdp"
          What is the difference between stdp and stdf ? (i didn't find anything about stdf in help predict)

          Comment


          • #6
            help regress postestimation##predict
            Best regards.

            Raymond Zhang
            Stata 17.0,MP

            Comment


            • #7
              You can also see https://www.statalist.org/forums/for...ear-regression.
              Best regards.

              Raymond Zhang
              Stata 17.0,MP

              Comment


              • #8
                We should use stdp instead of stdf.
                Code:
                 gen ln_x=ln(x)
                reg y ln_x
                predict yhat
                predict s,stdp
                gen low=yhat-1.96*s
                gen high=yhat+1.96*s
                twoway rarea low hi x, sort color(gs14)  ///        
                             ||scatter  y x ,sort ///        
                             || line yhat x,sort  ///        
                            ,legend(order(1 "CI" 2 3) row(1))
                Attached Files
                Last edited by Raymond Zhang; 20 Jan 2021, 12:09.
                Best regards.

                Raymond Zhang
                Stata 17.0,MP

                Comment


                • #9
                  I think it's ok with this !

                  But I don't understand why the standard prediction errors are bigger at the beginning and at the end. For me the dots are farther in the middle so the standard error should be bigger. Sorry I probably misunderstood how it works.

                  Comment


                  • #10
                    You're pooling all the data to get parameter values. The confidence interval calculations aren't localised but are based on the overall variability around the regression, not where that variability occurs.

                    Comment


                    • #11
                      That makes sense, I understand now. Thanks for your help!
                      Have a good day

                      Comment


                      • #12
                        So which kind of standard error do you choose at last?stdf or stdp?
                        Best regards.

                        Raymond Zhang
                        Stata 17.0,MP

                        Comment


                        • #13

                          Both will be useful to me I think. Thank you. I'm afraid to say a big mistake, but now I would like to work with the slope of my regression (therefore with the derivative). Is it possible to represent this on a graph with intervals like these?

                          Comment

                          Working...
                          X