Announcement

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

  • It seems that we cannot use tuples in tuples?

    I try to use tuples in the loop of tuples, however, it got some error: invalid 'y2'
    Does anyone know command tuples and give me a tips why the syntax is wrong?
    Is it because the citation of "`ntuples'", how to correct this?
    Code:
    tuples  x1 x2                           
            forvalues i = 1/`ntuples' {
            tempvar varIV`i' 
            gegen `varIV`i''=rowmean(`tuple`i'')
                    tuples  y1 y2  
                    forvalues k = 1/`ntuples' {
                    tempvar varDV`k'
                    gegen `varDV`k''=rowmean(`tuple`k'')

  • #2
    tuples is probably from SSC. The problem with your approach is that you create the local macro ntuples (and the local macros tuple1, tuple2, ...) repeatedly, once before the outer loop starts and then again before the inner loop starts. Therefore, once you enter the outer loop, you overwrite those local macros.

    There is a non-documented option, lmacname(), that allows you to specify a name other than tuple for the local macros to be created. The option is not allowed with the default python-based method to create the tuples. You can type something like

    Code:
    tuples x1 x2 , nopython lmacname(xvars)
    forvalues i = 1/`nxvars' {
        code referring to `xvars`i''
        tuples y1 y2 , nopython lmacname(yvars)
        forvalues j = 1/`nyvars' {
            code referring to `yvars`j''
        }
    }

    I will not guess what you are trying to do here but note that rowmean() does not make sense when fed only one variable. You might want to add tuples' min(2) option.
    Last edited by daniel klein; 20 Mar 2021, 05:55.

    Comment


    • #3
      Originally posted by daniel klein View Post
      tuples is probably from SSC. The problem with your approach is that you create the local macro ntuples (and the local macros tuple1, tuple2, ...) repeatedly, once before the outer loop starts and then again before the inner loop starts. Therefore, once you enter the outer loop, you overwrite those local macros.

      There is a non-documented option, lmacname(), that allows you to specify a name other than tuple for the local macros to be created. The option is not allowed with the default python-based method to create the tuples. You can type something like

      Code:
      tuples x1 x2 , nopython lmacname(xvars)
      forvalues i = 1/`nxvars' {
      code referring to `xvars`i''
      tuples y1 y2 , nopython lmacname(yvars)
      forvalues j = 1/`nyvars' {
      code referring to `yvars`j''
      }
      }

      I will not guess what you are trying to do here but note that rowmean() does not make sense when fed only one variable. You might want to add tuples' min(2) option.
      Thanks so much, Daniel!
      Is there any possibility to customize the local names when using python method? Nick Cox I notice that you are one author of tuples, can we upgrade this?

      Comment


      • #4
        That's correct, but long since my co-authors are running with this program and I am sitting in the theatre just approving.

        You should have noticed that daniel klein is also a co-author.

        The order of authors is serious, My role was just to get the thing started and phrase examples in terms of favourite metasyntactic variables frog newt toad. Along those lines I am aware that python isn't just a kind of snake. but I pass on any questions about it.

        Comment


        • #5
          Originally posted by daniel klein View Post
          tuples is probably from SSC. The problem with your approach is that you create the local macro ntuples (and the local macros tuple1, tuple2, ...) repeatedly, once before the outer loop starts and then again before the inner loop starts. Therefore, once you enter the outer loop, you overwrite those local macros.

          There is a non-documented option, lmacname(), that allows you to specify a name other than tuple for the local macros to be created. The option is not allowed with the default python-based method to create the tuples. You can type something like

          Code:
          tuples x1 x2 , nopython lmacname(xvars)
          forvalues i = 1/`nxvars' {
          code referring to `xvars`i''
          tuples y1 y2 , nopython lmacname(yvars)
          forvalues j = 1/`nyvars' {
          code referring to `yvars`j''
          }
          }

          I will not guess what you are trying to do here but note that rowmean() does not make sense when fed only one variable. You might want to add tuples' min(2) option.
          Oh, my god! I am sorry that I did't mention you are the co-authors, too. Do you have plans to upgrade this command for python method?

          Comment


          • #6
            I have added the lmacname() option for internal use to simplify comparing the tuples produced by different methods during testing. When I did that, I did not touch Joe Luchman's python script. The functionality should be fairly easy to implement but because of other obligations, that is not going to happen anytime soon from my side.

            For any reasonable number of items/variables, the (absolute) differences in running time should be trivial compared to the work that you typically do with each of the tuples. On my machine, a 20 item list needs about 45 sec. with the Python-based method and 80 sec. with the default Mata-based method.

            Comment


            • #7
              Hi Joe, do you have plans to modify the syntax so that we can customize the local name? Thanks so much! Joseph Luchman
              Last edited by Fred Lee; 20 Mar 2021, 19:34.

              Comment


              • #8
                Originally posted by daniel klein View Post
                tuples is probably from SSC. The problem with your approach is that you create the local macro ntuples (and the local macros tuple1, tuple2, ...) repeatedly, once before the outer loop starts and then again before the inner loop starts. Therefore, once you enter the outer loop, you overwrite those local macros.

                There is a non-documented option, lmacname(), that allows you to specify a name other than tuple for the local macros to be created. The option is not allowed with the default python-based method to create the tuples. You can type something like

                Code:
                tuples x1 x2 , nopython lmacname(xvars)
                forvalues i = 1/`nxvars' {
                code referring to `xvars`i''
                tuples y1 y2 , nopython lmacname(yvars)
                forvalues j = 1/`nyvars' {
                code referring to `yvars`j''
                }
                }

                I will not guess what you are trying to do here but note that rowmean() does not make sense when fed only one variable. You might want to add tuples' min(2) option.
                Hi Daniel, after some trial, I found the code shoud be:
                Code:
                 tuples x1 x2 , nopython lmacname(xvar)
                forvalues i = 1/`nxvars' {    
                code referring to `xvar`i''    
                tuples y1 y2 , nopython lmacname(yvar)    
                     forvalues j = 1/`nyvars' {        
                     code referring to `yvar`j''    
                }
                }
                Last edited by Fred Lee; 20 Mar 2021, 20:18.

                Comment


                • #9
                  Hi Joe, do you have plans to modify the syntax so that we can customize the local name? Thanks so much! Joseph Luchman
                  Agree with Daniel that it should be relatively easy to implement such a change. When development time permits will start to implement.
                  Joseph Nicholas Luchman, Ph.D., PStat® (American Statistical Association)
                  ----
                  Research Fellow
                  Fors Marsh

                  ----
                  Version 18.0 MP

                  Comment


                  • #10
                    Looking at the initial problem again, it seems as if the lists that are passed to tuples do not depend on each other. That is, the second tuples command will repeatedly produce the exact same result. If this so, then we obviously want to move both tuples commands outside of the loops as in

                    Code:
                    tuples x1 x2
                    tuples y1 y2, nopython lmacname(yvar)
                    
                    forvalues i = 1/`ntuples' {
                        code referring to `tuple`i''
                        forvalues j = 1/`nyvars' {
                            code referring to `yvar`j''
                        }
                    }
                    Depending on the problem, clever usage of the conditionals() option might produce the desired result with a single call to tuples.

                    Comment


                    • #11
                      Originally posted by Joseph Luchman View Post

                      Agree with Daniel that it should be relatively easy to implement such a change. When development time permits will start to implement.
                      Thank you!

                      Comment


                      • #12
                        Originally posted by daniel klein View Post
                        Looking at the initial problem again, it seems as if the lists that are passed to tuples do not depend on each other. That is, the second tuples command will repeatedly produce the exact same result. If this so, then we obviously want to move both tuples commands outside of the loops as in

                        Code:
                        tuples x1 x2
                        tuples y1 y2, nopython lmacname(yvar)
                        
                        forvalues i = 1/`ntuples' {
                        code referring to `tuple`i''
                        forvalues j = 1/`nyvars' {
                        code referring to `yvar`j''
                        }
                        }
                        Depending on the problem, clever usage of the conditionals() option might produce the desired result with a single call to tuples.
                        Great! I think this will save a lot of time!

                        Comment


                        • #13
                          Joseph Luchman Dear Joseph, I am wondering when are you available to upgrade tuples? Thanks so much!

                          Comment


                          • #14
                            Probably before the end of the summer season.

                            May also pull -tuples- development into GitHub (unless coauthors would prefer I not) to allow interested third-parties to make the change should they be interested in doing so and submit a pull request in the interim.

                            - joe
                            Joseph Nicholas Luchman, Ph.D., PStat® (American Statistical Association)
                            ----
                            Research Fellow
                            Fors Marsh

                            ----
                            Version 18.0 MP

                            Comment


                            • #15
                              @Joseph Luchman @daniel klein @Nick Cox Hi All, when use tuples, I use the conditions as below: tuples, cond(!(1&2) !(3&4) !(5&6) !(7&8) !(9&10))
                              It always get wrong when I include the position number 10, in other words, when the position number is larger than 9, the syntax cannot run successfully, is it because the limitation of the condition option?

                              Comment

                              Working...
                              X