Announcement

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

  • Issue Using A Colon in a Row Title in Matrix

    Hello all! I currently have a table that merges three panels. Each panel has a title "Panel A - X". However, I want to change the titles to "Panel A : X" (using a colon instead of a dash). When I do this however, STATA seems to automatically split the string and the resulting .tex file has and "&" in between "Panel A" and "X" which causes a fatal error.

    Below is my code which works correctly when the panel titles are "Panel A - X" or even "Panel A ; X" (using semicolons).

    Code:
        local outcomes1 "a b c d"
        local outcomes2 "e f g"
        local outcomes3 "h j k
    
        myregtablerowpanels using "Result/filename.tex", ///
                    outcome1(`outcomes1') panel1title(Panel A - X) ///
                    outcome2(`outcomes2') panel2title(Panel B - Y) ///
                    outcome3(`outcomes3') panel3title(Panel C - Z) ///
                    cluster(randomizationGroup_bylist) treatment(treated) ///
                    fe(randomizationGroup_bylist fu_enu) weight(inv_prob2)
    the code for myregtablerowpanels is the following:

    Code:
    program define myregtablerowpanels
    
        syntax using/ [if], Outcome1(varlist min=1) Outcome2(varlist min=1) [Outcome3(varlist min=1)] panel1title(string) panel2title(string) [panel3title(string)] Cluster(varname numeric) TREATment(varname numeric) [covars(varlist numeric)] fe(varlist min=1) Weight(varname)
        
        * PANEL A
          local varnum = wordcount("`outcome1'")
        matrix b_se1 = J(`varnum'+1,4,.)
        matrix colnames b_se1 = m1 m1_se m2 m2_se
        matrix rownames b_se1 = "\textbf{`panel1title'}" `outcome1'
        matrix n1 = J(`varnum'+1,2,.)    
        matrix control_mean1 = J(`varnum'+1,2,.)    
        matrix control_sd1 = J(`varnum'+1,2,.)
        
        local row = 1
        
        foreach var of varlist `outcome1' {        
            
            //display outcome
            di in red "Outcome: `var'"
            
            //unweighted
            reghdfe `var' `treatment', absorb(randomizationGroup_bylist) vce(cluster `cluster')
            mat tmp = get(_b)', vecdiag(cholesky(diag(vecdiag(get(VCE)))))'
            mat b_se1[`row'+1,1] = tmp[1,1...]
                    
            //weighted
            reghdfe `var' `treatment' [pw = `weight'], absorb(`fe') vce(cluster `cluster')
            mat tmp = get(_b)', vecdiag(cholesky(diag(vecdiag(get(VCE)))))'
            mat b_se1[`row'+1,3] = tmp[1,1...]
            mat n1[`row'+1,1] = `e(N)'        
            
            //add statisics: mean, sd, N in control
            reghdfe `var' `treatment', absorb(randomizationGroup_bylist) vce(cluster `cluster')
            qui sum `var' if e(sample) == 1 & `treatment' == 0
            local mean = r(mean)
            local sd = r(sd)        
            
            //Number obs, mean and sd in control
            mat n1[`row'+1,1] = `e(N)'        
            mat control_mean1[`row'+1,1] = `mean'        
            mat control_sd1[`row'+1,1] = `sd'                
            
            local ++row    
                
        }
        
        
        
            
        * PANEL B
          local varnum = wordcount("`outcome2'")
        matrix b_se2 = J(`varnum'+1,4,.)
        matrix colnames b_se2 = m1 m1_se m2 m2_se
        matrix rownames b_se2 = "\textbf{`panel2title'}" `outcome2'
        matrix n2 = J(`varnum'+1,2,.)    
        matrix control_mean2 = J(`varnum'+1,2,.)    
        matrix control_sd2 = J(`varnum'+1,2,.)
        
        local row = 1
        
        foreach var of varlist `outcome2' {        
            
            //display outcome
            di in red "Outcome: `var'"
            
            //unweighted
            reghdfe `var' `treatment', absorb(randomizationGroup_bylist) vce(cluster `cluster')
            mat tmp = get(_b)', vecdiag(cholesky(diag(vecdiag(get(VCE)))))'
            mat b_se2[`row'+1,1] = tmp[1,1...]
                    
            //weighted
            reghdfe `var' `treatment' [pw = `weight'], absorb(`fe') vce(cluster `cluster')
            mat tmp = get(_b)', vecdiag(cholesky(diag(vecdiag(get(VCE)))))'
            mat b_se2[`row'+1,3] = tmp[1,1...]    
            
            //add statisics: mean, sd, N in control
            reghdfe `var' `treatment', absorb(randomizationGroup_bylist) vce(cluster `cluster')
            qui sum `var' if e(sample) == 1 & `treatment' == 0
            local mean = r(mean)
            local sd = r(sd)        
            
            //Number obs, mean and sd in control
            mat n2[`row'+1,1] = `e(N)'        
            mat control_mean2[`row'+1,1] = `mean'        
            mat control_sd2[`row'+1,1] = `sd'                
                    
            local ++row    
                
        }
            
    if "`outcome3'" != "" {
    
            
        * PANEL C
          local varnum = wordcount("`outcome3'")
        matrix b_se3 = J(`varnum'+1,4,.)
        matrix colnames b_se3 = m1 m1_se m2 m2_se
        matrix rownames b_se3 = "\textbf{`panel3title'}" `outcome3'
        matrix n3 = J(`varnum'+1,2,.)    
        matrix control_mean3 = J(`varnum'+1,2,.)    
        matrix control_sd3 = J(`varnum'+1,2,.)
        
        local row = 1
        
        foreach var of varlist `outcome3' {        
            
            //display outcome
            di in red "Outcome: `var'"
            
            //unweighted
            reghdfe `var' `treatment', absorb(randomizationGroup_bylist) vce(cluster `cluster')
            mat tmp = get(_b)', vecdiag(cholesky(diag(vecdiag(get(VCE)))))'
            mat b_se3[`row'+1,1] = tmp[1,1...]
                    
            //weighted
            reghdfe `var' `treatment' [pw = `weight'], absorb(`fe') vce(cluster `cluster')
            mat tmp = get(_b)', vecdiag(cholesky(diag(vecdiag(get(VCE)))))'
            mat b_se3[`row'+1,3] = tmp[1,1...]    
            
            //add statisics: mean, sd, N in control
            reghdfe `var' `treatment', absorb(randomizationGroup_bylist) vce(cluster `cluster')
            qui sum `var' if e(sample) == 1 & `treatment' == 0
            local mean = r(mean)
            local sd = r(sd)        
            
            //Number obs, mean and sd in control
            mat n3[`row'+1,1] = `e(N)'        
            mat control_mean3[`row'+1,1] = `mean'        
            mat control_sd3[`row'+1,1] = `sd'                
                    
            local ++row    
                
        }
              
            
        //output table - Panel C
        frmttable, statmat(b_se3) substat(1) sdec(3) varlabels annotate(stars3) nocoltitl asymbol(*,**,***)
        frmttable, statmat(n3) substat(1) sdec(0) nocoltitl merge    
        frmttable, statmat(control_mean3) substat(1) sdec(2) nocoltitl merge
        frmttable, statmat(control_sd3) substat(1) sdec(2) nocoltitl merge store(C)    
        
        
    }    
        
        //output table - Panel B
        frmttable, statmat(b_se2) substat(1) sdec(3) varlabels annotate(stars2) nocoltitl asymbol(*,**,***)
        frmttable, statmat(n2) substat(1) sdec(0) nocoltitl merge    
        frmttable, statmat(control_mean2) substat(1) sdec(2) nocoltitl merge
        frmttable, statmat(control_sd2) substat(1) sdec(2) nocoltitl merge store(B)
        
        //output table - Panel A
        frmttable, statmat(b_se1) substat(1) sdec(3) varlabels annotate(stars1) nocoltitl asymbol(*,**,***)
        frmttable, statmat(n1) substat(1) sdec(0) nocoltitl merge
        frmttable, statmat(control_mean1) substat(1) sdec(2) nocoltitl merge
        frmttable, statmat(control_sd1) substat(1) sdec(2) nocoltitl merge
        
        frmttable, append(B)
        
    if "`outcome3'" != "" {    
        frmttable, append(C)
    }
    How can I solve this problem?
    Last edited by Adi JJahic; 08 Jul 2022, 09:16.

  • #2
    I am beyond unqualified to talk about this problem, but some the Statalisters who may be able to point you in the right direction (I suspect) are Bjarte Aagnes , daniel klein or maybe Maarten Buis if he's active. Additionally, you definitely want to provide a minimal worked example here- say with a pre-loaded dataset or something similar, since this will likely take an application to debug.


    Welcome to Statalist, Adi JJahic

    Comment


    • #3
      ref
      Code:
       
       matrix rownames b_se1 = "\textbf{`panel1title'}" `outcome1'
      help matrix rownames : A simple name is a sequence of 1 to 32 characters, which can include, for example, digits, spaces, and any Unicode letter; colons should not be used.

      Thus, use another character or search/replace the tex file, maybe uisng -filefilter-

      Comment


      • #4
        Bjarte Aagnes Your idea to use -filefilter- was perfect! Thank you so much.

        Comment

        Working...
        X