Announcement

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

  • Histogra

    Hi
    I want to create an histogram.

    this is the command:
    histogram dnascregdiacri_dif_days, start(0) bin(360) freq
    xscale(range(0 600))
    xtitle("Days Before Birth")
    ytitle("Frequency")
    title("Days Between Pregnancy Registration and Childbirth")
    graphregion(color(white))
    xline(90 180 270, lpattern(dash) lcolor(red))

    and this is the histogram: How can I remove the space between the zero and the start of the x axis?
    Thank you.
    Attached Files

  • #2
    Add:
    Code:
    plotregion(margin(0))

    Comment


    • #3
      Deleted. #2 provides a more accurate answer.

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        Deleted. #2 provides a more accurate answer.
        Thank you for your answer - Using the "twoway histogram" command instead I got this histogram
        Attached Files

        Comment


        • #5
          Originally posted by Ali Gokhan Yucel View Post
          Add:
          Code:
          plotregion(margin(0))
          Hi, thank you for your answer - I've added the command "plotregion(margin(0))" after my command, and I got the same graph. Where should I add the command?

          Comment


          • #6
            Please provide your data using dataex and your codes using code delimiters for reproducibility. See #12 in https://www.statalist.org/forums/help#stata

            Comment


            • #7
              Place it as an option within the command.

              Code:
              histogram dnascregdiacri_dif_days, start(0) bin(360) freq ///
              xscale(range(0 600)) xtitle("Days Before Birth") ytitle("Frequency") ///
              title("Days Between Pregnancy Registration and Childbirth") ///
              graphregion(color(white)) plotregion(margin(0)) ///
              xline(90 180 270, lpattern(dash) lcolor(red))

              Comment


              • #8
                Originally posted by Andrew Musau View Post
                Place it as an option within the command.

                Code:
                histogram dnascregdiacri_dif_days, start(0) bin(360) freq ///
                xscale(range(0 600)) xtitle("Days Before Birth") ytitle("Frequency") ///
                title("Days Between Pregnancy Registration and Childbirth") ///
                graphregion(color(white)) plotregion(margin(0)) ///
                xline(90 180 270, lpattern(dash) lcolor(red))
                It works!! Thank you

                Comment


                • #9
                  Originally posted by Ali Gokhan Yucel View Post
                  Please provide your data using dataex and your codes using code delimiters for reproducibility. See #12 in https://www.statalist.org/forums/help#stata
                  I resolved, thanks

                  Comment


                  • #10
                    See also

                    Code:
                    help spikeplot
                    I'd look at that outcome modulo 7.

                    Code:
                    gen remainder = mod(dnascregdiacri_dif_days, 7)
                    histogram remainder , discrete xla(0/6)

                    Comment


                    • #11
                      That is, there seems to be some fine structure in your histogram beyond the general skewness. If it's not a side-effect of weeks, look at the last digit of the variable.

                      Comment


                      • #12
                        Yes, the "bin(360)" might not be the right choice here if dnascregdiacri_dif_days is an integer. I think some of these bins represent two days and some represent one day. Try "discrete" or "discrete width(2)" instead.

                        Comment

                        Working...
                        X