Announcement

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

  • Problem showing xlabels in a twoway graph

    Hello.

    I am running a regression country by country, and I would like to show the significance of the coefficients in a twoway graph where each xlabel is a different country. I am running the following code:

    Code:
    encode iso3, gen(iso3_num)
    levelsof iso3_num, local(countries)
    gen coeff = .
    gen sig = .
    gen lb = .
    gen ub = .
    
    foreach c of local countries {
        
    reghdfe identity status_cash if iso3_num == `c' , abs(year group_country) vce(cluster group_country)
     scalar beta = _b[status_cash]
        scalar se = _se[status_cash]
        scalar pval = 1 - ttail(e(df_r), abs(beta / se))  // p-value computation
        
        // Compute confidence intervals
        scalar ci_lower = beta - invttail(e(df_r), 0.025) * se
        scalar ci_upper = beta + invttail(e(df_r), 0.025) * se
        
        replace coeff = beta if iso3_num == `c'
        replace sig = (pval < 0.05) if iso3_num == `c'
        replace lb = ci_lower if iso3_num == `c'
        replace ub = ci_upper if iso3_num == `c'
    }
    twoway (scatter coeff iso3_num, mcolor(blue)) ///
           (rcap lb ub iso3_num, lcolor(black)), ///
           yline(0, lcolor(red)) ///
           xlabel(, valuelabel angle(90)) ///
           title("Country-Specific Coefficients with Confidence Intervals") ///
           graphregion(margin(10 10 10 10))
    However, just the label of three countries appear. I do not think it is a matter of space, as I am writing the labels vertically. But I am not able to find a solution. Any help?

    This is an example of my dataset:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(year identity) str3 iso3 float(group_country status_cash) long iso3_num
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 85   .04476078 1
    2003 0 "BWA" 85   .04476078 1
    2003 . "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 85   .04476078 1
    2003 . "BWA" 93  .004048369 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 0 "BWA" 85   .04476078 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 85   .04476078 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 0 "BWA" 84  .002249904 1
    2003 1 "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 93  .004048369 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 1 "BWA" 85   .04476078 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 94 .0010226854 1
    2003 0 "BWA" 93  .004048369 1
    2003 . "BWA" 85   .04476078 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 1 "BWA" 85   .04476078 1
    2003 1 "BWA" 89  .006098506 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 0 "BWA" 93  .004048369 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 85   .04476078 1
    2003 0 "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 0 "BWA" 85   .04476078 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 0 "BWA" 85   .04476078 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 0 "BWA" 86 .0006186686 1
    2003 0 "BWA" 91   .01554987 1
    2003 1 "BWA" 93  .004048369 1
    2003 1 "BWA" 85   .04476078 1
    2003 0 "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 85   .04476078 1
    2003 1 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 1 "BWA" 85   .04476078 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 94 .0010226854 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 93  .004048369 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 . "BWA" 85   .04476078 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 85   .04476078 1
    2003 1 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 1 "BWA" 85   .04476078 1
    2003 0 "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 85   .04476078 1
    2003 . "BWA" 85   .04476078 1
    2003 . "BWA" 85   .04476078 1
    2003 . "BWA" 91   .01554987 1
    2003 1 "BWA" 91   .01554987 1
    2003 0 "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    2003 . "BWA" 91   .01554987 1
    end
    label values iso3_num iso3_num
    label def iso3_num 1 "BWA", modify
    Thank you!
    Last edited by Diego Malo; 04 Dec 2024, 11:41.

  • #2
    There is only one country in your example data, so whatever the problem is cannot be explored with that data.

    Comment


    • #3
      Suppose there're 25 countries in your data, just specify the xlabel numlist.
      Code:
      twoway (scatter coeff iso3_num, mcolor(blue)) ///
             (rcap lb ub iso3_num, lcolor(black)), ///
             yline(0, lcolor(red)) ///
             xlabel(1(1)25, valuelabel angle(90)) ///
             title("Country-Specific Coefficients with Confidence Intervals") ///
             graphregion(margin(10 10 10 10))

      Comment


      • #4
        It works Chen Samulsion . Thank you so much!

        Comment

        Working...
        X