Announcement

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

  • Graph

    Hello, I need to create the following graph attached in the file.

    I am using the following code, but I'm getting the same output. Please help.

    Thanks

    * Calculate the mean and standard deviation of pm2p5_1
    summarize pm2p5_1

    * Store the mean and standard deviation in local macros
    local mean = r(mean)
    local sd = r(sd)

    * Generate a new variable that is the z-score of pm2p5_1
    generate pm2p5_1_z = (pm2p5_1 - `mean') / `sd'


    * Assuming the variable names are mean_pm25 and height_zscore
    scatter haz06 pm2p5_1_z, mcolor(blue) ///
    || lfit haz06 pm2p5_1_z, color(red) ///
    legend(off) ///
    xtitle("Mean PM2.5 in First Trimester (z-scores)") ///
    ytitle("Height-for-age (z-scores)") ///
    graphregion(color(white)) plotregion(color(white))



    Data



    . dataex pm2p5_1 haz06 , count(10000)

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(pm2p5_1 haz06)
    1.6778737739202506e-08               -3.49
    2.5761926747588366e-08                -.58
     3.859374875246417e-08                   .
     1.819043616940413e-08                   .
     3.859374875246417e-08                   .
     3.698110971155913e-08                   .
    3.4469341835663074e-08               -1.75
     3.841774503319892e-08               -2.12
     4.803728381241039e-08               -3.81
     4.543198784672938e-08                   .
     4.426735082885306e-08                   .
     6.122811686980286e-08               -2.18
     3.712600601223118e-08                -.77
     3.625873919017026e-08                   .
     6.498681198965056e-08                   .
     5.145495222801459e-08                2.09
     5.255860662586405e-08               -1.01
     4.758344269982077e-08                   .
     5.114501055499233e-08                   .
     5.601563306496416e-08                   .
     6.415111758570791e-08               -3.13
     6.228555041451614e-08                1.94
     9.552010794502684e-08               -2.46
     6.406260705040322e-08                   .
     5.326179061227599e-08                   .
     8.132716495040785e-08                   .
    5.0271151479973125e-08                -.78
     6.102866354301077e-08                   .
     7.374746981504416e-08               -3.95
     6.122811686980287e-08               -1.09
     7.384696699641579e-08                   .
    1.1487645056854839e-07 -3.5500000000000003
     8.485802197638887e-08                   .
     7.583054557352149e-08                   .
     9.491302229435484e-08               -1.47
     6.048887733288531e-08                   .
     7.148759711066307e-08               -2.22
     6.614322169520612e-08                -3.4
     1.339637064420123e-07                 .09
     7.733205477908988e-08               -2.08
    1.0468778182392478e-07 -2.5100000000000002
    5.2692887116039425e-08                   .
     4.958076682029569e-08                   .
     7.041977874668458e-08                   .
     6.423788855689965e-08                   .
     5.977532869937277e-08                   .
     5.638540142396955e-08                -.09
     9.546549088844083e-08                   .
    1.1397622335304663e-07                   .
    1.0359917767377112e-07                1.48
     9.546549088844083e-08                -1.7
     6.838571706003582e-08               -2.33
      9.14790297943548e-08                   .
     9.836159149529566e-08                   .
      6.20740347141577e-08                 .05
     6.901679891932283e-08                   .
     6.370377943848567e-08                1.03
     8.627983146998207e-08                   .
     8.956671601120073e-08                   .
      6.54025045327061e-08               -1.98
     6.857735384408599e-08                   .
    1.2014637863088617e-07 -1.8800000000000001
    5.5229553049014354e-08                   .
     7.799490974986557e-08                -.59
      7.52193242437724e-08               -1.48
     7.342280557616488e-08                1.23
      5.38508246747312e-08               -1.77
      4.23154202830197e-08                   .
    4.9629372968189946e-08                   .
     5.351488620675751e-08 -3.2800000000000002
     9.534384819225065e-08                   .
     6.375695234408602e-08                -.98
     5.731062955017922e-08               -2.17
     4.722731176008066e-08                   .
    1.3529075801492402e-07                   .
     6.769242914650538e-08               -1.06
     6.609835613530467e-08                   .
     5.240379229023296e-08               -4.64
     4.318707687589603e-08                   .
     8.595055649381721e-08                -.05
     7.641571848745519e-08               -1.25
     1.207120124833148e-07               -2.06
     6.490122866129033e-08               -2.12
     6.298224775806453e-08               -1.16
     5.601563306496416e-08               -2.96
    1.1486119639112905e-07                   .
     7.074180502556965e-08                   .
     5.918849191845879e-08               -2.41
    1.0048808145564521e-07                -.91
      8.35183240972222e-08                 .02
    1.4477506037679215e-07               -2.14
    1.0777452306067591e-07               -3.09
      6.51309560594086e-08               -1.55
    1.4853359901785712e-07               -1.81
    1.6267349088805686e-07                 .17
      1.33457130209492e-07                   .
       9.7104709297043e-08                   .
     7.860276151299282e-08               -1.46
    1.6873756619802863e-07                   .
     8.505465373969533e-08                   .
     5.370975674386201e-08                   .
     7.050705087797617e-08                   .
     8.286659947087811e-08               -3.12
     6.631136389560932e-08               -2.14
     1.564143698027074e-07               -4.55
     1.209613991063172e-07               -1.31
    1.9852775537186372e-07                   .
      2.07123064016129e-07                   .
     9.103217491621862e-08                 -.8
    1.9588393606950844e-07                2.49
    1.1666867141935484e-07                2.21
    1.2167696436005503e-07                -.81
      9.96815298315412e-08                   .
    1.2140511884274196e-07                   .
    1.5261345484350995e-07               -1.61
     9.700851689336917e-08               -1.71
     9.346396765367384e-08                 .42
    1.4286187840437785e-07                   .
     1.386947679521889e-07                   .
     1.739770722956989e-07               -1.79
      1.34942029561828e-07               -3.04
    1.2067244166935484e-07 -3.0300000000000002
    1.4963949151676907e-07                   .
    1.9779472060915912e-07                   .
     8.611324152638888e-08                 .18
    1.2501986193772399e-07                -.12
     9.686271691218634e-08               -1.21
     1.496394915167691e-07                2.48
     9.162911097318865e-08                   .
     7.547076648682794e-08                   .
    1.0600463655107523e-07                   .
      9.65924885481631e-08                   .
     8.945314715143365e-08 -2.0100000000000002
    
    end
    ------------------ copy up to and including the previous line ------------------


    Attached Files

  • #2
    This is the Binscatter plot for relationship between Height-for-age and Mean PM2.5 in first trimester (z-scores).

    Comment


    • #3
      I'm not sure what your question is. Your code runs without error messages and produces the kind of graph you want it to. I suppose you are unhappy because the graph seems to suggest that the relationship between haz06 and pmp2p5_1_1 is both noisy and, perhaps, in the opposite direction from the specimen you show in #1.

      There is nothing wrong with the code. So the problem lies with your data. The first thing that jumps out at me is that nearly 50% of the observations have missing values for haz06. So that may well be a cause of serious bias in your analysis. Why are there so many missing values? What process creates the missingness? Could it be that it is somewhat selectively leading to missing values in a way that produces this bias. I do note that the mean pm2p5_1_z in the complete cases is +0.04, whereas in the data where haz06 is missing, the mean pm2p5_1_z is -0.05. Sounds like a substantial bias.

      Alternatively, how confident are you in the accuracy of both the height for each measurements/calculations and the PM2.5 measurements?

      Alternatively, is it possible the source from which you obtained your specimen graph has got it wrong?

      Comment

      Working...
      X