Announcement

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

  • #16
    I usually have a bigger class of task or assignment, from which the individual information is pulled out. An example structure for renaming could be:

    Code:
    clear all
    
    class Pair {
      string from
      string to
    }
    
    class Plan {
      array content
    }
    
    .renaming=.Plan.new
    .tmp=.Pair.new
    
    .renaming.content[1]=.tmp
    .renaming.content[1].from="a1"
    .renaming.content[1].to="b1"
    .renaming.content[2]=.tmp
    .renaming.content[2].from="a2"
    .renaming.content[2].to="b2"
    .renaming.content[3]=.tmp
    .renaming.content[3].from="a3"
    .renaming.content[3].to="b3"
    .renaming.content[4]=.tmp
    .renaming.content[4].from="a4"
    .renaming.content[4].to="b4"
    
    display "`.renaming.content[1].from'"
    display "`.renaming.content[2].from'"
    display "`.renaming.content[3].from'"
    display "`.renaming.content[4].from'"
    
    .third=.renaming.content[3]
    
    display "`.third.from'"

    It looks intimidating at first, but is actually very simple. The important part is that one can work explicitly with pairs of values (e.g. the use of .third).

    Best, Sergiy Radyakin

    Comment


    • #17
      Alan,

      Thanks; this is much closer to what I had in mind, although with a lot of punctuation to keep track of. It's too bad that more attention is not paid to this feature in courses and here on Statalist. A good addition to the "toolbox"!

      Regards,
      Joe

      Comment


      • #18
        Originally posted by Nick Cox View Post
        John has the right idea. In this example it could be just

        Code:
        forval j = 1/4 {
        scatter A`j' B`j' , name(`j')
        }
        I added a name() option: otherwise each plot just disappears as the next is drawn.
        Hi everyone,

        what if I wanted to generate a loop whose argument consisted of 3 different varlists, in order to estimate, for instance, 3 different probit models?
        I though I could generate three local macros and then estimate, but I am wrong, e.g.,
        local one var1 2 vr3 //fictional names
        local two var2 ar6 r9
        local three r4 ar3 ar8
        #delimit;
        foreach x of local one two three {;
        use data.dta, clear;
        probit DV `x';
        };
        I searched through the forum, but failed to find a solution. I will appreciate feedback on this (apparently easy) issue.
        V
        Victor Cruz

        Comment


        • #19
          Anyone interested in Victor's question should follow https://www.statalist.org/forums/for...arlists-macros

          Comment

          Working...
          X