Announcement

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

  • how to graph the confidence interval

    Hello!
    I was trying to create a hypothesis test based on this model:
    1. yi = β0 + β1xi1 + ui
    this model have 1000 observations and also this conditions:
    1. xi1 ∼U(0,1) ui ∼N(0,1) β0 =1 β1 =2
    So we can see that xi has a uniform distribution, ui a normal distribution and β0 and β1 are constants. To start using this values in Stata we use this commands:
    Code:
    set obs 1000
    generate U = rnormal()
    generate x = uniform()
    gen b0 = 1
    gen b1 = 2
    
    gen y= b0+(b1*x)+U
    Following this steps we continuos working on it an we finally got the confidence interval values for 90%, 95% and 99%. But our big problem its how we can graphic the ranges all in one graph, I upload an example. As you can see we need the three percentage on the same graph but we do not know the right commands to do something like the image.
    Attached Files

  • #2
    I don't see how that graph relates to the simulation you are doing. I suspect that there is either a language problem at work here, or that you have much bigger problems than just making this graph.

    However creating that graph in Stata can be done. Is this what you are looking for?

    Code:
    local x1 = invnormal(0.01) - (invnormal(0.01) - -4)/2
    local y1 = normalden(`x1')
    local x2 = invnormal(0.05) - (invnormal(0.05) - invnormal(0.01))/2
    local y2 = normalden(`x2')/2
    local x3 = invnormal(0.10) - (invnormal(0.10) - invnormal(0.05))/2
    local y3 = normalden(`x3')/2
    
    twoway function density = normalden(x), range(-4 `= invnormal(0.10)') recast(area) color(sand%30) || ///
           function density = normalden(x), range(-4 `= invnormal(0.05)') recast(area) color(sand%30) || ///
           function density = normalden(x), range(-4 `= invnormal(0.01)') recast(area) color(sand%30) || ///
           function density = normalden(x), range(-4 4) scheme(s1color) legend(off) || ///
           scatteri `y1' `x1' (12) "5%" ///
                    `y2' `x2' (0) "5%" ///
                    `y3' `x3' (0) "5%", msymbol(none)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	53.5 KB
ID:	1605863

    Attached Files
    Last edited by Maarten Buis; 26 Apr 2021, 01:27.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank Maarten, that is exactly what I was looking for. The only problem it is that I do not understand this part:
      Code:
       
       local x1 = invnormal(0.01) - (invnormal(0.01) - -4)/2 local y1 = normalden(`x1') local x2 = invnormal(0.05) - (invnormal(0.05) - invnormal(0.01))/2 local y2 = normalden(`x2')/2 local x3 = invnormal(0.10) - (invnormal(0.10) - invnormal(0.05))/2 local y3 = normalden(`x3')/2
      Because we need to graph this intervals CI on the same graph that you sent:

      90% [-1.226e+1 , 1.226e+13]
      95% [-1.877e+13 , 1.877e+13]
      99% [-2.232e+13 , 2.232e+13]

      We got the values as a variable and probably we just have to write them on the code for the graph, but if you can explain us how to do it correctly would be more useful.
      And thank you again.

      Comment


      • #4
        I recreated the graph you showed. That graph does not represent a confidence interval. So, I have no idea how that graph relates to your text.

        Can you explain to me why you think that graph tells your audience something useful about a confidence interval?

        Can you tell us exactly where those confidence intervals come from?

        Who is your intended audience?
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          So here it is the activity that we are trying to replicate in Stata. so the commands that we already have are:
          Code:
            /*A*/
          
          clear all
          set more off
          set obs 1000
          generate U = rnormal()
          generate x = uniform()
          gen b0 = 1
          gen b1 = 2
          
          gen y= b0+(b1*x)+U
          
          reg y x
          
          scatter y x
          twoway (scatter y x) (lfit y x)
          
            /*B*/
          gen betha0g= _b[_cons]
          gen betha1g= _b[x]
          
          gen ygorro= betha0g+(betha1g*x)
          
          gen Ugorro=y-ygorro
          
          gen sumugorro=sum((Ugorro)^2)
          gen ugorrosum = sumugorro[1000]
          
          
          gen DSU= (1/(1000-1-1))*(ugorrosum)
          
          gen t= ((betha1g-b1)/DSU)
          
          display ttail(1,t)
          
          gen ICinf= betha1g-(1.96*DSU)
          gen ICsup= betha1g+(1.96*DSU)
          
          gen ICinf90= betha1g-(1.28*DSU)
          gen ICsup90= betha1g+(1.28*DSU)
          
          display ICinf90,ICsup90
          
          //95% - 1.96
          gen ICinf95= betha1g-(1.96*DSU)
          gen ICsup95= betha1g+(1.96*DSU)
          
          display ICinf95,ICsup95
          
          //99% - 2.33
          gen ICinf99= betha1g-(2.33*DSU)
          gen ICsup99= betha1g+(2.33*DSU)
          
          display ICinf99,ICsup99
          That is why we need to do a graph with the three CI 90%,95% and 99%
          Last edited by Josefa Zaro; 26 Apr 2021, 12:22.

          Comment


          • #6
            OK, so this is a homework question. As you can read in the FAQ, (black bar at the top of this page), homework questions aren't answered on this site. The only hint I can give you that the numbers in #3 are completely wrong.
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              it is not a homework we are just testing and old paper and trying to replicate it based on our new study, we do not know the commands that the autor used so we are just discovering them by the replication.

              Comment


              • #8
                Then I don't understand what you want to do. The things that are in the text and the code you gave us are so standard, and are implemented already (and much better) in any standard statistics program (including Stata). There is no need to try to program that again from scratch. If this is a real project, then you should not have done anything that you have done. I suspect you need to book a couple of hours with a statistics coach to go through your entire project from the very beginning, as there are so many problems with what you have shown us, that I don't know where to start addressing all of these in a format like this forum. You don't need a specialist in Stata or advanced techniques, but someone with a solid understanding and real experience with applying basic statistics in real research (specialist often tend to forget the basics...). I suspect that you will find at the end of that session, that your problem is much easier than you thought and that the biggest problem you are having now is that you are overthinking it. However, I suspect you will also find that you will probably have throw everything you have done thus far away.

                It is not that I don't want to help you, it is just that each medium has its own strengths and weaknesses and solving some problems work better in one medium, while solving others work better in another. So you are very welcome on this site, it is just that another medium is probably better suited to your problems. In your case I suspect that one needs to spent quite some time to find out what the real problems are combined with a refresher course. Saying that you may need a refresher course sounds bad, but it is not: knowledge on statistics is pretty much a "use it or loose it" skill, and most people, for very legitimate reasons, don't use it. So they have lost that skill. Fortunately, it is usually easy and quick to recover. Finding out what the problems are and giving a refresher course statistics is best done face-to-face (or more realistically, video conference). Statalist is better suited for more limited technical problems. So, when you get your project back on the rails, then you are very welcome to ask those there.
                Last edited by Maarten Buis; 27 Apr 2021, 01:49.
                ---------------------------------
                Maarten L. Buis
                University of Konstanz
                Department of history and sociology
                box 40
                78457 Konstanz
                Germany
                http://www.maartenbuis.nl
                ---------------------------------

                Comment

                Working...
                X