Announcement

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

  • ereturn list of variables using loop

    Dear all,
    In my code I generate 5564 matrix of size (1000,1).
    I was able to generate the matrix using the code with T=5564 and R=1000:

    Code:
    for(t=1;t<=T;t++){        
        stri = strofreal(t)
        ST2=1+R*(t-1)                            
        FI2=t*R            
        st_matrix("s_ind_"+stri,s_ind[|ST2,.\FI2,.|])
    }
    However, I am trying to create an ereturn for each matrix.
    Usually I would simply write
    Code:
    ereturn matrix s_ind_1=s_ind_1 
    ...
    ereturn matrix s_ind_5564=s_ind_5564
    Is there a way of doing so with a loop?
    Thank you all

  • #2
    I can't imagine any scenario where you would want to ereturn 5000 matrices. Have no idea what things will fail there.

    Thus, my question is what do you *really* want to accomplish? (so we can avoid the xy problem: http://xyproblem.info/ )

    Comment


    • #3
      I need to extract individual probabilities in my code. I have a sample of 1000 individuals for each of 5564 municipalities, hence I have a vector of 5,564,000 lines that I would like to extract using st_matrix, which obviously exceeds maximum matsize. To solve this I am trying to extract 5564 vectors, one for each municipality. I will later move this data to matlab where I can analyse the results I want.
      I hope this explanation helped.

      Comment


      • #4
        Then, can you just copy it to the dataset? EG: set the obs. to 5,560,000, and then copy with st_store to a variable. Then outsheet the data to comma-separated values that you can load from matlab

        Comment


        • #5
          I don't think I can do that. I generate this values in the middle of an estimation, but they are not stored in the dataset. What I'm trying to do is exactly to be able to copy it to somewhere else. I think it would be easier to use ereturn than to use st_store.

          Comment


          • #6
            Sergio Correia The link in #2 is excellent. It belongs in our FAQ Advice. Thanks!

            Comment


            • #7
              Sergio,
              I tried to use st_store but wat not able to create a variable. The problem is in my code I use a database of 5564 municipalities and them the code loads another database of demographic information. This one with 5,564,000 observations. Don't know if this might be the reason why i'm not being able to.

              I tried to loop using strofreal as bellow:

              Code:
              for(t=1;t<=T;t++){    
               ereturn matrix "s_ind_" + strofreal(t)="s_ind_" + strofreal(t)
              }
              but the error: invalid syntax appears.

              I'm running out of ideas.
              Any thoughts?

              Thanks a lot for your help!

              Comment


              • #8
                I tried creating a matrix of 5564 pointers, one for each matrix.
                But the problem is I can't store a matrix of pointers for it is neither a real matrix nor a string matrix. Would there be a solution for this problem?

                Comment


                • #9
                  I tried to use st_store but wat not able to create a variable. The problem is in my code I use a database of 5564 municipalities and them the code loads another database of demographic information. This one with 5,564,000 observations
                  What *exactly* did you do?

                  Look, if I were you I would discard the approach of storing 5000 matrices/pointers/etc. and just store a single matrix of the correct size. For that, what exactly is in each matrix, whats the size?

                  Comment


                  • #10
                    I think I solved the problem. My code takes about 5 days to run, due to the size of the database, so by the end of the week I'll know. If it's working I'll post the result.

                    Comment

                    Working...
                    X