Announcement

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

  • Renaming local contents

    Hi all,

    I am performing the following loop:

    Code:
    foreach rec of local recall {
        tokenize `rec'
        local endog_1 "General Recalls" // dummy_1 = withdrawns, dummy_2 = recalls, dummy_3 = recalled_class_one, dummy_4 = recalled_class_two 
        local endog_2 "Recalls Class I" 
        local endog_3 "Recalls Class II" 
        local aggr "product firm atc2"
        foreach agg of local aggr {
    
            use "/Users/federiconutarelli/Desktop/PhD/Lavoro_Riccaboni/DATi_USA/Pharma_project_2019 /abnormal_values/demeaned_DBs/stacked_mean_`agg'_`rec'.dta", clear
    
            collapse (mean) mean_avt var_avt, by(rescaled)
            gen lower = mean_avt - 1.96*(sqrt(var_avt)/11)
            gen higher = mean_avt + 1.96*(sqrt(var_avt)/11)
            drop if rescaled ==.
            
             
            local `1' "`endog_1'"
            local `2' "`endog_2'"
            local `3' "`endog_3'"
            
            
            *Grafico:
            twoway (connected lower higher mean_avt rescaled,lpattern(solid)), legend(label(1 "Lower C.I.") label(2 "Upper C.I.")label(3 "AV_t `agg' `rec'")) yline(0,lcolor(black)) xline(0,lwidth(thin) lpattern(shortdash)) note("Recall Year = 0") ytitle(abnormal value) xtitle(Year) xlabel(-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11) name(pre_post_gr_`agg'_`rec', replace)
    
                
        }
    }
    Now: the local recall consists of 3 names: dummy_2 dummy_3 dummy_4. They are necessary since each of the databases in the loop are called after these names as you can see from:

    Code:
    use "/Users/federiconutarelli/Desktop/PhD/Lavoro_Riccaboni/DATi_USA/Pharma_project_2019 /abnormal_values/demeaned_DBs/stacked_mean_`agg'_`rec'.dta", clear
    Now, dummy_2, dummy_3 and dummy_4 are not variables that appear in such databases (the databases are composed by 3 variables: av_t, mean_avt and rescaled_year). I use twoway connected to such databases but am forced to label the legend with dummy_2 dummy_3 and dummy_4 (label(3 "AV_t `agg' `rec'")). What if I would like to put instead of

    Code:
    label(3 "AV_t `agg' `rec'")
    something that gives me: "General Recalls" instead of dummy_2, "Recalls Calss I" instead of dummy_3 and "Recalls Class II" instead of dummy_4 in the graph? (i.e. renaming the content of the local recall which contains names that are not variables, without changing the name in the next iteration of the loop).

    Thank you very much

  • #2
    Perhaps this will point you in a useful direction.
    Code:
    local recall dummy_2 dummy_3 dummy_4
    local label_2 "General Recalls"
    local label_3 "Recalls Class I"
    local label_4 "Recalls Class II"
    
    local aggr product firm atc2
    
    foreach rec of local recall {
        foreach agg of local aggr {
            local rex : subinstr local rec "dummy_" "label_"
            local rex ``rex''
            display `" label(3 "AV_t `agg' `rex'") "'
        }
    }
    Code:
     label(3 "AV_t product General Recalls")
     label(3 "AV_t firm General Recalls")
     label(3 "AV_t atc2 General Recalls")
     label(3 "AV_t product Recalls Class I")
     label(3 "AV_t firm Recalls Class I")
     label(3 "AV_t atc2 Recalls Class I")
     label(3 "AV_t product Recalls Class II")
     label(3 "AV_t firm Recalls Class II")
     label(3 "AV_t atc2 Recalls Class II")

    Comment


    • #3
      Thank you very much William. Really appreciated your help!

      Comment

      Working...
      X