Announcement

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

  • Need help in ado syntax

    I'm trying to develop a program for an estimation method. I have a dependent variable, a list of independent variables, some weighing variables, and a list of moments. In this situation, I'm trying to develop syntax and a list of tempvar. My program looks like (although I'm not quite sure, if it is the right format):

    program define something
    syntax depvar indepvar (wtvar) moments(values) // (wtvar) = list of weighing variables and moments(value) = list of values i.e., values of moments //
    My questions:
    (1) Is it the right form to write syntax for this problem?
    (2) How can I generate tempvar (W) in which each variable is the deviated form of each variable in (wtvar) and the corresponding argument in moments(values). For example, W_i = wtvar_i - moments[1,i]?

    Thank you
    end

  • #2
    Depending on which estimation method you want to use, you should look at the help files for either GMM
    Code:
    help gmm
    or Maximum Likelihood
    Code:
    help mlmethod
    . Furthermore, you should read the help file for the syntax command itself and the corrosponding PDF documentation about Programming in Stata and the example for the syntax command given in the PDF documentation.
    Code:
    help syntax
    .
    1. To directly answer your questions: Your presented syntax would not work directly. You would probably code something like
      Code:
      syntax varlist(min=2), moments(numlist) [wtvar(varlist)]
    2. You would probably code something like
      Code:
      	local i 0
      	foreach var of varlist `wtvar'{
      	local ++i
      	tempvar W_`var'
      	gen `W_`var'' = `var' - `:word `i' of `moments''

    Comment


    • #3
      Thank you so much Sven-Kristjan Bormann for your quick replay. Since I'm new in programming, I guess I'll face a lot of problems. Let me come up with something. I will keep up to date my problems.

      Comment


      • #4
        Further help needed:

        Could you please tell me why the following loop only works for the first observation? I worked on it based on (#2) suggested by Sven-Kristjan Bormann.


        clear all
        program define svywt

        syntax varlist, moments(numlist)
        local i 0

        foreach var of varlist `varlist'{
        local ++i
        tempvar W_`var'
        gen `W_`var'' = `var' - `:word `i' of `moments''

        di `W_`var''

        }

        end


        sysuse auto, clear

        svywt price weight, moments(20 25)

        Thank you a lot.
        Last edited by Rabiul Islam; 21 Feb 2020, 14:24.

        Comment


        • #5
          Sorry for post #4. Problems now solved!

          Comment


          • #6
            A minor correction from my side:
            Instead of
            Code:
             foreach var of varlist `wt'{ ...
            I could have coded also
            Code:
            foreach var of local `wt'{...
            The reason is that the varlist in `wt' is already expanded, so the varlist does not be expanded once again in the foreach-loop. It is minor detail, but this way is shown in the documentation and a bit more efficient.

            Comment


            • #7
              Thank you again Sven-Kristjan Bormann

              Comment

              Working...
              X