Announcement

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

  • why this code is wrong?

    estpost tabulate Q10
    esttab, cells("b pct") tex
    Stata shows :
    invalid syntax
    in not found

    But this code works for some other variables.

  • #2
    You'll increase your chance of a helpful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output and sample data using dataex. I don't even know if estpost or esttab is generating the error. If we can replicate the problem, then we have a much better chance of helping you.

    estpost is user written. If it works for some variables and not others, then the likely problem is something in the tabulate part of the command. Is b a legitimate option after tabulate? The esttab documentation on cells() doesn't mention this kind of options.

    Comment


    • #3
      Code:
      label variable q25 "Gender"
      estpost tabulate q25
      esttab, cells("b pct") tex
      Above codes works. However,

      Code:
      label list q10
      tabulate q10, missing
      
      generate Q10 = (q10==1 | q10==2)
      replace Q10=2 if missing(q10)
      label define Q10 0 "Correct Answer" ///
                       1 "Wrong Answer" ///
                       2 "Don't Know"
      label values Q10 Q10
      estpost tabulate Q10
      esttab, cells("b pct") tex
      After these codes, Stata says
      HTML Code:
      invalid syntax
      in not found
      I am glad to share my dataset by using dataex. but I don't know how to do that.

      Comment


      • #4
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str17 responseid byte(q10 q25)
        "R_07olc7RfV4QoiOJ" 3 1
        "R_0AHixEJ5QkFlXah" 3 2
        "R_0DtFbTIGolHL22R" 3 1
        "R_0JJgNpi2HthEfK1" 3 1
        "R_0OIugt5thDAck13" 3 1
        "R_10MoMzFBSZhVJin" 3 2
        "R_10N32NeGqhSOVjp" 3 1
        "R_10pwKkqQqLwRVQW" 2 1
        "R_10q74QS1XVOlhOy" 3 1
        "R_10qPgsB4h3Ht4Ec" 3 1
        "R_115AIunMB6ZKPPR" 3 1
        "R_11WU5Fi2yhVFzsC" 3 1
        "R_11XTWBHdJ7eDL5M" 3 1
        "R_11d5bz5K858gZXF" 3 1
        "R_11hf3CdzklbcJd7" 3 1
        "R_124udSczHFF6dL8" 2 1
        "R_12GdaU1RKdEofOd" 3 1
        "R_12sadEIKYiXQ00R" 3 1
        "R_12tjCsMMfQyy6zY" 3 1
        "R_12yFLbkzIgFtHt6" 3 2
        end
        label values q10 q10
        label def q10 2 "Less than $102", modify
        label def q10 3 "More than $102", modify
        label values q25 q25
        label def q25 1 "Female", modify
        label def q25 2 "Male", modify

        Comment


        • #5
          esttab is from Stata Journal, authored by Ben Jann (refer to the FAQs on the requirement to identify the source of user-written commands). I suspect that there is part of your code that you are not showing us. Copy and paste the full commands that you enter and the resulting Stata error as I do below. As you can see, I get no such error.

          Code:
          . * Example generated by -dataex-. To install: ssc install dataex
          
          . 
          . clear
          
          . 
          . input str17 responseid byte(q10 q25)
          
                      responseid       q10       q25
            1. 
          . "R_07olc7RfV4QoiOJ" 3 1
            2. 
          . "R_0AHixEJ5QkFlXah" 3 2
            3. 
          . "R_0DtFbTIGolHL22R" 3 1
            4. 
          . "R_0JJgNpi2HthEfK1" 3 1
            5. 
          . "R_0OIugt5thDAck13" 3 1
            6. 
          . "R_10MoMzFBSZhVJin" 3 2
            7. 
          . "R_10N32NeGqhSOVjp" 3 1
            8. 
          . "R_10pwKkqQqLwRVQW" 2 1
            9. 
          . "R_10q74QS1XVOlhOy" 3 1
           10. 
          . "R_10qPgsB4h3Ht4Ec" 3 1
           11. 
          . "R_115AIunMB6ZKPPR" 3 1
           12. 
          . "R_11WU5Fi2yhVFzsC" 3 1
           13. 
          . "R_11XTWBHdJ7eDL5M" 3 1
           14. 
          . "R_11d5bz5K858gZXF" 3 1
           15. 
          . "R_11hf3CdzklbcJd7" 3 1
           16. 
          . "R_124udSczHFF6dL8" 2 1
           17. 
          . "R_12GdaU1RKdEofOd" 3 1
           18. 
          . "R_12sadEIKYiXQ00R" 3 1
           19. 
          . "R_12tjCsMMfQyy6zY" 3 1
           20. 
          . "R_12yFLbkzIgFtHt6" 3 2
           21. 
          . end
          
          . 
          . label values q10 q10
          
          . 
          . label def q10 2 "Less than $102", modify
          
          . 
          . label def q10 3 "More than $102", modify
          
          . 
          . label values q25 q25
          
          . 
          . label def q25 1 "Female", modify
          
          . 
          . label def q25 2 "Male", modify
          
          . 
          . 
          . 
          . label list q10
          q10:
                     2 Less than $102
                     3 More than $102
          
          . 
          . tabulate q10, missing
          
                     q10 |      Freq.     Percent        Cum.
          ---------------+-----------------------------------
          Less than $102 |          2       10.00       10.00
          More than $102 |         18       90.00      100.00
          ---------------+-----------------------------------
                   Total |         20      100.00
          
          . 
          . generate Q10 = (q10==1 | q10==2)
          
          . 
          . replace Q10=2 if missing(q10)
          (0 real changes made)
          
          . 
          . label define Q10 0 "Correct Answer" 1 "Wrong Answer" 2 "Don't Know"
          
          . 
          . label values Q10 Q10
          
          . 
          . estpost tabulate Q10
          
                   Q10 |      e(b)     e(pct)  e(cumpct) 
          -------------+---------------------------------
          Correct_An~r |        18         90         90 
          Wrong_Answer |         2         10        100 
          -------------+---------------------------------
                 Total |        20        100            
          
          . 
          . esttab, cells("b pct") tex
          
          {
          \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
          \begin{tabular}{l*{1}{cc}}
          \hline\hline
                      &\multicolumn{2}{c}{(1)}  \\
                      &\multicolumn{2}{c}{Q10}  \\
                      &           b&         pct\\
          \hline
          Correct Answer&          18&          90\\
          Wrong Answer&           2&          10\\
          Total       &          20&         100\\
          \hline
          \(N\)       &          20&            \\
          \hline\hline
          \end{tabular}
          }

          Comment

          Working...
          X