Announcement

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

  • Invalid name with reg and coefplot

    Hi! I am new to this Community, this is my first post. I am trying to create some coefplots with stata using regressions (I am using reghdfestd version 5 so it works) and after this code I find: "__000001- invalid name r(198);

    end of do-file r(198); ". I do not have a variable called like that and I am not trying to name one like that. What is the reason for the error?
    "gl y_ivs meancact indextab trust_out gl y_gps negrecip

    gl fe1ivs ${febaseivs} yearb country year age gl fe1gps ${febasegps} yearb country year age

    gl g1 "0 5" gl g2 "6 17" gl g3 "18 25" gl g4 "26 32" gl g5 "33 40" gl g6 "41 50" gl g7 "51 60" gl g8 "61 70" gl g9 "71 200"

    u "temp",replace foreach b in ivs gps{ u "temp/b'",replace mer m:1 country year yearb using "temp/2democracy/tot/demAge",keepus(dem1* dem2*) keep(1 3) nogen foreach y in ${y_b'}{

    local w = 0 matrix coef = J(9, 3, .) matrix coln coef = coefficients1 lcl1 ucl1 //para guardar coeficiente lowe bound y upper bound matrix rown coef = "Epidemic exposure (0-5)" "Epidemic exposure (6-17)" "Epidemic exposure (18-25)" "Epidemic exposure (26-32)" "Epidemic exposure (33-40)" "Epidemic exposure (41-50)" "Epidemic exposure (51-60)" "Epidemic exposure (61-70)" "Epidemic exposure +71" forv g=1/9 { loc w = `w'+1 loc min=real(word("${g`g'}",1)) loc max=real(word("${g`g'}",2)) preserve drop if !inrange(year-yearb,`min',`max') reghdfestd `y' dem1g`g' if inrange(year-yearb,`min',`max'), a(${fe1`b'}) cl(${cl1}) version(5) mat os = r(table) mat coef[`w',1] = os[1,1] mat coef[`w',2] = os[5,1] mat coef[`w',3] = os[6,1] restore } coefplot (matrix(coef[,1]), ci((coef[,2] coef[,3]))), title("Effect of Exposure to Sickness on `y'",size(medsmall)) graphregion(color(white)) bgcolor(white) horizontal yline(1 2 3 4 5 6 7 8 9, lpattern(shortdash) lcolor(gray)) /// xline(0) ciopts(lwidth(vthick) lcolor(emidblue)) grid(between glpattern(shortdash)) msymbol(O) mfcolor(white) mlabel mlabposition(6) ylabel(,labs(vsmall)) gr export "${savef}/ages`y'.pdf",replace }
    }".

  • #2
    It seems to be related to an intern process of the reghdfestd function renaming some variable because I found "rename meancact __000001" using "set trace on".

    Comment


    • #3
      Cross-posted at https://www.reddit.com/r/stata/comme...sion_coefplot/

      Please note: it's a rule at Reddit and a request here to tell people about cross-posting.

      Meanwhile, your code should be pasted between

      delimiters to be readable.

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Cross-posted at https://www.reddit.com/r/stata/comme...sion_coefplot/

        Please note: it's a rule at Reddit and a request here to tell people about cross-posting.

        Meanwhile, your code should be pasted between



        delimiters to be readable.
        Thanks Nick!

        Code:
         
        gl y_ivs meancact indextab trust_out
        gl y_gps negrecip
        
        gl fe1ivs ${febaseivs} yearb country year age 
        gl fe1gps ${febasegps} yearb country year age 
        
        gl g1 "0 5"
        gl g2 "6 17"
        gl g3 "18 25"
        gl g4 "26 32"
        gl g5 "33 40"
        gl g6 "41 50"
        gl g7 "51 60"
        gl g8 "61 70"
        gl g9 "71 200"
        
        u "temp",replace
        foreach b in ivs gps{
        set trace on
        u "temp/`b'",replace
        mer m:1 country year yearb using "temp/2democracy/tot/demAge",keepus(dem1* dem2*) keep(1 3) nogen
          foreach y in ${y_`b'}{ 
                
                local w = 0
                
                matrix coef = J(9, 3, .)
                matrix coln coef = coefficients1 lcl1 ucl1 //para guardar coeficiente lower bound y upper bound
                matrix rown coef = "Epidemic exposure (0-5)" "Epidemic exposure (6-17)" "Epidemic exposure (18-25)" "Epidemic exposure (26-32)" "Epidemic exposure (33-40)" "Epidemic exposure (41-50)" "Epidemic exposure (51-60)" "Epidemic exposure (61-70)" "Epidemic exposure +71"
                
                forv g=1/9 { 
                    
                    loc w = `w'+1    
                    loc min=real(word("${g`g'}",1))
                    loc max=real(word("${g`g'}",2))
                    preserve
                    
                    drop if !inrange(year-yearb,`min',`max')
                
                    reghdfestd `y' dem1g`g' [aw=weight], a(${fe1`b'}) cl(${cl1}) version(5)                
                        
                    mat os = r(table)
                    mat coef[`w',1] = os[1,1]
                    mat coef[`w',2] = os[5,1]
                    mat coef[`w',3] = os[6,1]
                    
                    restore
                }
                coefplot (matrix(coef[,1]), ci((coef[,2] coef[,3]))), title("Effect of Exposure to Democracy on `y'",size(medsmall)) graphregion(color(white)) bgcolor(white) horizontal yline(1 2 3 4 5 6 7 8 9, lpattern(shortdash) lcolor(gray)) ///
                xline(0) ciopts(lwidth(vthick) lcolor(emidblue)) grid(between glpattern(shortdash)) msymbol(O) mfcolor(white) mlabel mlabposition(6) ylabel(,labs(vsmall)) 
                gr export "${savef}/ages`y'.pdf",replace        
        }
        }
        Last edited by Martin Loriente; 14 Jan 2024, 14:20.

        Comment


        • #5
          Should have been

          Code:
          * code goes here
          delimiters.

          What is this?

          Code:
           
           reghdfestd
          That's my guess for most suspect.
          Last edited by Nick Cox; 14 Jan 2024, 15:06.

          Comment


          • #6
            Yes, it seems to be a problem with "reghdfestd". It is a function to make regressions standardized with fixed effects that had an update a month ago and did not work anymore, so I was using it 5th version but it seems to make trouble too. I just changed it to "reghdfe". Thanks Nick!

            Comment

            Working...
            X