Announcement

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

  • #16
    For anyone watching that line

    Code:
    generate index = string(_n) in 1/14
    would be better as

    Code:
    generate index = _n in 1/14
    (If Stata were to sort "1" ... "9" "10" ... "14" it would produce "1" "10" "11" ... "9".)

    It would be even better to give informative names through value labels of index.

    Comment


    • #17
      This is exactly how I proceeded.

      But now I fail on twisting the value labels on the x-axis.

      I use this code for the graph:

      Code:
      graph bar (asis) Corr_ER_Neg, over(Index_Corr) title(Correlation: Return and negative words) ylabel (-0.5 -0.25 0 0.25 0.5 , angle(0))
      It shows the Correlations on the y-axis and value labels on the x-axis. Currently value labels are covering each other. This is why I would like to turn them around with "angle"

      I tried the following:

      Code:
      graph bar (asis) Corr_ER_Neg, over(Index_Corr) title(Korrelation: ER und Anteil negativer Wörter) ylabel (-0.5 -0.25 0 0.25 0.5 , angle(0)) xlabel (, angle (45))
      Stata returns me the following message: xlabels(, angle (45)) not allowed, xaxis1 does not exist

      Any further advice?
      Last edited by Magdalena Hetterich; 05 Oct 2016, 08:29.

      Comment


      • #18
        -graph hbar- is a better bet than -graph bar- whenever you have struggles like this.

        Comment


        • #19
          Is there no other solution? I would prefer not having changed the x- and y-axis.

          I tried:

          Code:
          graph hbar (asis) Corr_ER_Neg, over(Index_Corr) title(Corrrelation: Return and negative words) ylabel (-0.5 -0.25 0 0.25 0.5 , angle(0)) xlabel(, angle(45)) vertical name(Corr_ER_Neg)
          The option "vertical" changed axis again, but I still get the return code: xlabels(, angle(45)) not allowed, xaxis1 does not exist

          Comment


          • #20
            No; hbar and then vertical just mean bar.

            graph bar and graph hbar are not graph twoway so many twoway options just do not apply to them.

            Follow the help and manual entry for graph bar which explain that these graphs have (a) a y axis and (b) a categorical axis (not considered to be an x axis).

            Seems strange, possibly, but that's how it is.

            Also, it is documented how to fiddle with label options.

            We don't have your data to play with but consider these examples.

            The second is a horrible graph, but seems closer to what you are asking for.

            Code:
            sysuse auto, clear
            gen corr = .
            gen what = ""
            local j = 0
            
            quietly foreach v of var price rep78-gear_ratio {
               corr mpg `v'
               replace corr = r(rho) in `++j'
               replace what = "`v'" in `j'
            }
              
            graph hbar (asis) corr, over(what, sort(1))
            
            graph bar (asis) corr, over(what, sort(1) label(ang(45)))

            Comment


            • #21
              Thanks a lot!
              I am sorry, I am not allowed to post data, but this was a perfect solution.
              The only thing I changed, was to sort by an Index-variable, as I wanted to present results it in a predefined order (from one day to 12 months).

              Comment


              • #22
                Dear Statalist-Users,

                I worked on this topic and have a new question now.

                I managed to plot correlations differenciated by 36 industry sectors. The graph shows the level of correlation on the y-axis and the return period on the categorial axis. In total I get 36 graphs. This is the code I use for that:

                Code:
                // Preperation for plotting correlations
                generate Index_Corr =_n in 1/14
                label var Index_Corr "return periods"
                label define Index_Corr_1 ///
                    1 "1 day" 2 "1 weeks" 3 "1 month" 4 "2 months" 5 "3 months" 6 "4 months" 7 "5 months" ///
                    8 "6 months" 9 "7 months" 10 "8 months" 11 "9 months" 12 "10 months" 13 "11 months" 14 "12 months"
                label values Index_Corr Index_Corr_1
                
                
                *2.1.1) Correlations: Negative words and Return
                
                // ER_Neg
                
                forvalues i = 1/36 {
                    generate Corr_ER_Neg_`i'=.
                }
                
                
                forvalues i = 1/36 {
                local j = 0  
                    foreach x of varlist ER_1_Day- ER_12_Month {
                        quietly corr `x' Neg_Words if Industry_ID==`i'      
                        replace Corr_ER_Neg_`i' = r(rho) in `++j'
                    }    
                
                    set scheme s2mono
                        graph bar (asis) Corr_ER_Neg_`i' ///
                            , over(Index_Corr, sort(Index_Corr) label(ang(45))) title("Correlation: Return and negative words in industry sector `i'") ///
                            ylabel (-0.5 -0.25 0 0.25 0.5 , angle(0)) ///
                            blabel(bar, position(outside) format(%9.2f)) name(Corr_ER_Neg_`i', replace) saving(Corr_ER_Neg_`i', replace)
                        graph export Corr_ER_Neg_`i'.wmf, replace
                    
                        
                }

                Now I would wish to plot the results in a different order. The categorical axis should show all 36 industry sectors and the y axis should show level of correlation. Each graph would be differentiated by return periods, so in total I would have 14 graphs.
                I think the correlation results, I would like to plot, are already stored in the local, but I have absolutely no idea how to adress them in the
                Code:
                graph bar
                command....

                Can anyone help? I would be very grateful for any suggestions!

                Magdalena

                Comment

                Working...
                X