Announcement

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

  • #16
    Another one:

    Code:
    local foo q1 q2 q3 q4 q5 q6 q7 q8 q9
    
    gettoken this rest : foo 
    
    while "`this'" != "" { 
        di "`this'" 
        gettoken this rest : rest 
    }

    Comment


    • #17
      Dear Hemanshu & Nick,

      My thanks again for your helpful examples.
      I exercise them for my typical issue of retrieving elements from the uirt result macro e(depvar), without using the (inefficient code) macro shift, like:
      Code:
      * Example
      webuse masc2, clear
      qui uirt q*
      
      * using uirt result macro(s)
      
      * Hemanshu Kumar (#14): Set tokens manually without using macro shift
      tokenize `e(depvar)'
      forvalues i = 1/`e(N_items)' {
          dis "``i''"
      }
      
      * Nick Cox (#15): Another useful approach is:
      local element `e(depvar)'
      forval w = 1/`e(N_items)'  { 
          di "`: word `w' of `element''"
      }
      
      * Nick Cox (#16): Another one:
      local element `e(depvar)'
      gettoken this rest : element
      while "`this'" != "" { 
          di "`this'" 
          gettoken this rest : rest
      }
      Each alternative produces the required display of the variables used.
      I prefer the last alternative that Nick offered as it only requires the result macro while the code is executed for as long as there are (unused) elements in it.
      http://publicationslist.org/eric.melse

      Comment


      • #18
        I prefer the last alternative that Nick offered as it only requires the result macro
        In the versions drawn from #14 and #15, there is no particular need for the e(N_items) macro. We can obtain the number of elements to iterate through by simply counting the words in e(depvar)like so:

        Code:
        local num_items: word count `e(depvar)'

        Comment


        • #19
          Originally posted by ericmelse View Post
          I prefer the last alternative that Nick offered as it only requires the result macro while the code is executed for as long as there are (unused) elements in it.
          If this is your criterion, there is no need for tokenize in the first place. A straightforward (and faster than while) approach is
          Code:
          foreach x in `e(depvar)' {
              display "`x'"
          }

          Comment


          • #20
            Well, Daniel, 'Douze Points' for your most concise alternative to collect the items of the uirt model!
            http://publicationslist.org/eric.melse

            Comment


            • #21
              daniel klein is naturally correct.

              I think we have a fairly standard trade-off: ericmelse is (helpfully) focusing on a specific answerable question and getting answers to and around that. But the wider context of why he wants to do what he does and what comes next is not clear to me. Perhaps the question is proxy for some more complicated question.

              For my part, I've never used uirt and have no idea why you might want to parse the dependent variable list. Don't you know that any way?

              Comment


              • #22
                Dear Nick,
                My apologies for cloaking my objective (unwillingly). But, it is rather technical. I am working on code to enhance the functionality of uirt's post estimation command uirt_icc to create separate plots with all response curves for each item.
                Stata's internal command irt can do this rather well, like:
                Code:
                * Example
                webuse masc2, clear
                qui irt grm q*
                * create the first response option curves of all items in a single plot
                irtgraph icc 0.q1 0.q2 0.q3 0.q4 0.q5 0.q6 0.q7 0.q8
                Which results in:
                Click image for larger version

Name:	Example_irt_icc_1st_response_.png
Views:	1
Size:	67.0 KB
ID:	1777742



                But, for this to get going using uirt results I have to reset the labels of a result matrix with the names of the variables used.
                Hence, my need to collect these from the result macro `e(depvar)' (not wanting to do this manually).
                So, at this point it is still 'experimental' and 'work in progress'.
                For more on uirt I refer to: Kondratek, B. (2022). uirt: A command for unidimensional IRT modeling. The Stata Journal, 22(2), 243-268.
                Last edited by ericmelse; 20 May 2025, 11:13.
                http://publicationslist.org/eric.melse

                Comment


                • #23
                  Makes sense; thanks for the context.

                  Comment

                  Working...
                  X