Announcement

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

  • How to understand this program and syntax ?

    HI! I am new in STATA and I was asked to translate this program in python but I can not understand what these command are doing in details. In general this program will be used for the GMM moment conditions, that is
    Code:
    gmm gmm_acf, nequations(1) nparameters(2) twostep instruments(k L.l, noconstant) from(b1 0.4 b2 0.6) conv_maxiter(100) technique(bfgs 10 dfp 10)
    But my problem is about how to understand this gmm_acf program.
    Code:
    program gmm_acf
    syntax varlist [if], at(name)
    quietly {
        local 1 : word 1 of `varlist'
        tempvar f w eta
        generate float `f' = `at'[1,1]*l + `at'[1,2]*k 
        generate float `w' = phi - `f'
        regress `w' cL.`w' cL.`w'#cL.`w' cL.`w'#cL.`w'#cL.`w'
        predict float `eta', residuals
        replace `eta' = `eta' + eps
        replace `1' = `eta'
        }
        end
    My more specific confusions:
    1. What is the meaning of at(name) in
    Code:
    syntax varlist [if], at(name)
    ? I read the syntax file, I didn't find the "name" option.
    2. `1' is the first element of "varlist" that will be used in later?
    3. how to understand
    Code:
    generate float `f' = `at'[1,1]*l + `at'[1,2]*k
    . Why [1,1] and [1,2] here?

    Thank you so much !!!!!!!!

  • #2

    In program gmm_acf the local macro at will contain the name of a matrix (help syntax##optional_namelist).

    Comment


    • #3
      Correct on your question 2.

      at() is the name the programmer gave to an option which expects a matrix to be named.

      My interpretation is that the matrix is at least 1 row and 2 columns in the sense that its elements [1,1] and [1,2] are used so that the matrix either is or might as well as be a 1 x 2 row vector. Note that in Stata (as opposed to Mata) vectors are not supported as such but must be matrices with 1 row and 1 or more columns or 1 column and 1 or more rows.

      Beyond that, I hope you have access to some documentation or that it is otherwise obvious what are phi, k, l, eps -- which must exist before the program is called as numeric variables or scalars.

      Number 1 and lower case l are so close that I would be wary of using either in a command (unless the use of number 1 is clear in context) .

      Comment


      • #4
        The program that you see here is a program defined by the user to evaluate the moment equations. Essentially, the original author of this code defined a program called -gmm_acf- which is passed into (and used by) the -gmm- command, just like you might pass a lambda function into a different python function as an argument. When you run -gmm-, it will call -gmm_acf- and pass in the varlist, as well as any options that the -gmm- command doesn't recognize.

        The at() option is a special option. It is used to pass a vector of parameters at which the movement is evaluated. You are required to give an at() option to write a movement evaluator program like -gmm_acf-. The vector itself is generated within the -gmm- command, which is why you don't see at() as an option for the -gmm- command.

        Notice in the -gmm- command you set nparameters(2). This means that the parameter vector (or matrix) passed into at() will be 1 by 2. [1, 1] refers to the first parameter and [1, 2] refers to the second parameter. Since the parameter vector is of length 1 by nparameters(2), the first number in square brackets should always be 1.

        1 is indeed the first variable name in the varlist, as you can see from this line:

        Code:
        local 1 : word 1 of `varlist'
        I think this line is a bit awkward for a few reasons, but especially because the name of the local (i.e., `1') isn't very descriptive and it may be difficult to distinguish at a glance from the value 1. I don't think this is a mistake, but just keep in mind that whoever wrote this wasn't perfect (then again, who is?). When a local is referenced elsewhere in a program or do file it is usually surrounded by compound quotes. Compound quotes consist of a back-tick character (just above the tab key) followed by a single quote just to the right of the semicolon on your keyboard. We can see that the local is used exactly one other time in the last line of the program, when the variable is replaced with the content of `eta'.

        Code:
        replace `1' = `eta'
        I strongly suggest that you read the documentation. I would especially look through the section Moment-evaluator program version under the remarks heading carefully. You've been given a difficult task, especially for someone new to Stata. My condolences. I'm hoping you were asked to do this because you really know your way around python's statsmodels.gmm class, or you are in for a difficult time.

        Comment


        • #5
          Originally posted by Bjarte Aagnes View Post
          In program gmm_acf the local macro at will contain the name of a matrix (help syntax##optional_namelist).
          Thank you so much!

          Comment


          • #6
            Originally posted by Nick Cox View Post
            Correct on your question 2.

            at() is the name the programmer gave to an option which expects a matrix to be named.

            My interpretation is that the matrix is at least 1 row and 2 columns in the sense that its elements [1,1] and [1,2] are used so that the matrix either is or might as well as be a 1 x 2 row vector. Note that in Stata (as opposed to Mata) vectors are not supported as such but must be matrices with 1 row and 1 or more columns or 1 column and 1 or more rows.

            Beyond that, I hope you have access to some documentation or that it is otherwise obvious what are phi, k, l, eps -- which must exist before the program is called as numeric variables or scalars.

            Number 1 and lower case l are so close that I would be wary of using either in a command (unless the use of number 1 is clear in context) .
            Thank you!!

            Comment


            • #7
              Originally posted by Daniel Schaefer View Post
              The program that you see here is a program defined by the user to evaluate the moment equations. Essentially, the original author of this code defined a program called -gmm_acf- which is passed into (and used by) the -gmm- command, just like you might pass a lambda function into a different python function as an argument. When you run -gmm-, it will call -gmm_acf- and pass in the varlist, as well as any options that the -gmm- command doesn't recognize.

              The at() option is a special option. It is used to pass a vector of parameters at which the movement is evaluated. You are required to give an at() option to write a movement evaluator program like -gmm_acf-. The vector itself is generated within the -gmm- command, which is why you don't see at() as an option for the -gmm- command.

              Notice in the -gmm- command you set nparameters(2). This means that the parameter vector (or matrix) passed into at() will be 1 by 2. [1, 1] refers to the first parameter and [1, 2] refers to the second parameter. Since the parameter vector is of length 1 by nparameters(2), the first number in square brackets should always be 1.

              1 is indeed the first variable name in the varlist, as you can see from this line:

              Code:
              local 1 : word 1 of `varlist'
              I think this line is a bit awkward for a few reasons, but especially because the name of the local (i.e., `1') isn't very descriptive and it may be difficult to distinguish at a glance from the value 1. I don't think this is a mistake, but just keep in mind that whoever wrote this wasn't perfect (then again, who is?). When a local is referenced elsewhere in a program or do file it is usually surrounded by compound quotes. Compound quotes consist of a back-tick character (just above the tab key) followed by a single quote just to the right of the semicolon on your keyboard. We can see that the local is used exactly one other time in the last line of the program, when the variable is replaced with the content of `eta'.

              Code:
              replace `1' = `eta'
              I strongly suggest that you read the documentation. I would especially look through the section Moment-evaluator program version under the remarks heading carefully. You've been given a difficult task, especially for someone new to Stata. My condolences. I'm hoping you were asked to do this because you really know your way around python's statsmodels.gmm class, or you are in for a difficult time.

              Thank you so much! Your reply is really really helpful! I know my expectation for this now. It is sad, I don't know anything about python, not better than STATA. My Prof. said there are lots learning materials about python, so I can learn it by myself. And I am a Phd student just learned GMM in the class but my fellowship relying on my RA work like this lol.

              Comment

              Working...
              X