Announcement

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

  • How to generate a new multivariable?

    generate prodvars= logY3a logY4a logY3asq

    invalid 'logY4a'

  • #2
    What are you trying to do here? You have, on the right side of the equation, just three variables with no operators connecting them. You have to tell Stata what to do with these variables.

    Comment


    • #3
      generate prodvars= logY3a logY4a logY3asq
      generate envars= Z1a Z12 Z13

      global ylist logtc
      global xlist=[prodvars, envars]

      I want to create new variables(prodvars and enviers) then take them as global x. How can I do this correctly?

      Comment


      • #4
        There's only one way I'm able to make sense of what you are saying here: you are misusing the term "variable." You are not looking to create new variables prodvars and envars. Rather you are looking to create a list of variables stored in a global macro. This has nothing to do with generate.

        Code:
        global prodvars logY3a logY4a logY3asq
        global envars Z1a Z12 Z13
        global xlist $prodvars $envars
        You could then follow that with a command like -regress $ylist $xlist- to get the equivalent of -regress logtc logY3a logY4a logY3asq Z1a Z12 Z13-. Is that what you're trying to do?

        That said, you shouldn't be doing this with global macros. They are an inherently unsafe programming practice that should only be used as a last resort when nothing else will serve the purposes. If you are trying to make lists of variables to pass on to commands like -regress-, you should use local macros instead:

        Code:
        local ylist logtc
        local prodvars logY3a logY4a logy3asq
        local envars Z1a Z12 Z13
        log xlist `prodvars' `envars'
        
        // AND PERHAPS THEN USE THEM AS
        regress `ylist' `xlist'

        Global macros can interfere with, or be interfered with by global macros of the same name in other programs that are running. Since you often call programs that call other programs that call other programs, and so on, you can never be sure when you work with a global macro that you are not tampering with something somewhere else in the chain that you are unaware of. This problem does not arise often, but when it does, finding the source of the error is extremely difficult. If you ever once have this happen to you, you will not want it to happen again. Better to avoid the use of global macros whenever possible. For what it's worth, in over 25 years of Stata programming, I have only found it necessary to use a global macro on two occasions.
        Last edited by Clyde Schechter; 01 Mar 2020, 19:01.

        Comment


        • #5
          Thank you Clyde Schechter. It is exactly what I want. But then I tried reg $ylist $xlist it is really working for simple regression. But I have to quantile regression, but when I writing qreg $ylist $xlist, quantile(.3) it returns following error:

          convergence not achieved.
          VCE computation failed; try increasing the maximum number of iterations or try
          bsqreg.

          Comment


          • #6
            #5 is a quite separate problem that may arise from your data or (apart from Stata's suggestion) may signal trying to fit something too complicated.

            Note that whether it's regress or qreg once you go (say)

            Code:
            qreg $ylist $xlist
            only the first variable in $ylist is taken as a response; all the others become predictors.

            Comment


            • #7
              Thank you Nick Cox. But I have to show my quant regression at least 3 different tau. Is there any other way?

              Comment


              • #8
                If a quantile regression doesn't work, I don't know another way to get a quantile regression. Are you that you don't want say


                Code:
                qreg logY3a  Z1a Z12 Z13

                Comment

                Working...
                X