Announcement

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

  • What xtset creates is global or local?

    Consider the following example code.
    Code:
    . quietly webuse nlswork, clear
    
    . quietly xtset idcode year
    
    . display "`r(panelvar)'"
    idcode
    
    . display "$r(panelvar)"
    (panelvar)
    According to this code, the return of the command xtset looks like a "local" macro.

    However, I found a confusing thing, let's see the results below.
    Code:
    . mata: st_local("r(panelvar)")
      
    
    . mata: st_global("r(panelvar)")
      idcode
    Here, only the st_global mata code returns a result.

    So is r(panelvar) local or global?

  • #2
    Originally posted by Minch Park View Post
    Consider the following example code.
    [CODE]
    . quietly webuse nlswork, clear

    . quietly xtset idcode year

    . display "`r(panelvar)'"
    idcode

    So is r(panelvar) local or global?
    It's an r() macro. You reference such macros using single quotes, same as a local macro. For what -st_global()- allows, see

    Code:
    help mf_st_global

    Comment


    • #3
      Andrew Musau According to the help file, the st_global command obtains strings from "global" macro. Then, is the r() macro essentially global?

      Comment


      • #4
        Originally posted by Minch Park View Post
        According to the help file, the st_global command obtains strings from "global" macro.
        If you read the documentation as I said, it is not exclusive to global macros.

        Syntax

        string scalar st_global(string scalar name)

        void st_global(string scalar name, string scalar contents)

        void st_global(string scalar name, string scalar contents, string
        scalar hcat)

        string scalar st_global_hcat(string scalar name)


        where

        1. name is to contain

        a. global macro such as "myname"

        b. r() macro such as "r(names)"

        c. e() macro such as "e(cmd)"

        d. s() macro such as "s(vars)"

        e. c() macro such as "c(current_date)"

        f. dataset characteristic such as "_dta[date]"

        g. variable characteristic such as "mpg[note]"
        You are referencing (a), but you have (b) - (g).

        Comment


        • #5
          Andrew Musau I am sorry. I missed the details. Thank you for your answer! Now, I totally understood that!

          Comment


          • #6
            r-class results are not themselves either local or global macros. They share some properties with each of those.

            As I understand it, it's not the setting of characteristics that is the main deal of tsset and xtset.

            Comment


            • #7
              Delete “not”!

              Comment


              • #8
                Nick Cox Thank you! It was a great help in improving my understanding of Stata macro.

                Comment

                Working...
                X