Announcement

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

  • What is the c(current_date) ?

    This question may sounds naive but what is the c(current_date)? is it a scalar of string or a local?

    disp c(current_date) indicates that c(current_date) is just a string scalar but disp "`c(current_date)'" shows that it is a local macro

    what is the truth here?

  • #2
    Using `' around a returned value forces Stata to evaluate it first. This can be convenient when the returned value contains a number and you want to feed the returned value to an option of a subsequent command that requires a number. If you enter it without `' that command will complain.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks, Buis! So the `' does not necessarily means that c(current_date) is a local? I also find that we can use disp `r(N)' after summarize command. Can we treat the c(current_date) as a scalar?

      Comment


      • #4
        As far as I understand it (hope I am correct) you can use r(), c(), e() and s() scalars and macros without single quotes, wherever Stata allows an expression. Thus,

        Code:
        display c(current_date)
        will work, as will

        Code:
        generate foo = c(alpha)
        although the latter is a nonsensical example. Because display and generate evaluate expressions, there is no need to use single quotes to force evaluation. Given this, it should not be surprising that

        Code:
        forvalues j = 1/r(N) {
        
        }
        results in an invalid syntax error, as Stata does not expect, and in fact not allow, an expression in the forvalues command. Typing

        Code:
        forvalues j = 1/`r(N)' {
        
        }
        will work fine, as will

        Code:
        forvalues j = 1/`= r(N)' {
        
        }
        as both force evaluation before forvalues interprets the numlist it expects to see. Note that I did not enclose r(N) in quotes in the second example.

        I hope this helps.

        Best
        Daniel
        Last edited by daniel klein; 16 Apr 2015, 02:07.

        Comment

        Working...
        X