Announcement

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

  • Unexpected end of file message

    Hello,

    I keep receiving a message of "unexpected end of file message" when I am running this code. I have tried adding the word "end" and putting "}" at the end, but then I receive an "invalid syntax" message. I am new with STATA so I am probably missing something obvious. Any help would be awesome. Thanks!

    Code:

    foreach `var' of varlist age sex cbrd breed intact town tsign vax hosp snap vom dia eat drnk pain ttx hr rr tempc temp wi wf bg pcv ts mmc mmm crt pqual psync ment bcs dehyd txtot out cout {
    quietly, su `va', d
    scalar mean_`var' = r(mean)
    scalar sd_`var'= r(sd)
    scalar median_`var' = r(p50)
    scalar min_`var' = r(min)
    scalar max_`var' = r(max)
    scalar sample_`var' = r(N)
    display "`var'"_column(30)round(mean_`var',0.1)




  • #2
    I don't think local quotes (` ') around the `var' are necessary. Make sure the end quote "}" is on a line by itself. Also, ought your line "quietly, su `va', d" be "quietly su `var', d"?
    Last edited by Josh Clothiaux; 04 May 2017, 11:10.

    Comment


    • #3
      Just to note the alternative here of using tabstat. Consider this

      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . tabstat mpg weight price, s(mean sd median min max N) format(%2.1f)
      
         stats |       mpg    weight     price
      ---------+------------------------------
          mean |      21.3    3019.5    6165.3
            sd |       5.8     777.2    2949.5
           p50 |      20.0    3190.0    5006.5
           min |      12.0    1760.0    3291.0
           max |      41.0    4840.0   15906.0
             N |      74.0      74.0      74.0
      ----------------------------------------
      
      . tabstat mpg weight price, s(mean sd median min max N) format(%2.1f) c(s)
      
          variable |      mean        sd       p50       min       max         N
      -------------+------------------------------------------------------------
               mpg |      21.3       5.8      20.0      12.0      41.0      74.0
            weight |    3019.5     777.2    3190.0    1760.0    4840.0      74.0
             price |    6165.3    2949.5    5006.5    3291.0   15906.0      74.0
      --------------------------------------------------------------------------
      Also, note that display with a format say %9.1f is a much better way of getting one decimal place than round()

      (I have no fix within tabstat for the decimal place on the sample size.)

      Comment


      • #4
        Thank you Nick Cox that worked perfectly!

        Comment

        Working...
        X