Announcement

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

  • #16
    Did you perhaps neglect to review the output of
    Code:
    help in
    for an explanation of the function of the in clause? Stata's help and documentation should be the first stop when you need advice, as the Statalist FAQ linked to from the top of the page advises us.

    The correct syntax is
    Code:
    frame results1: replace results1= r(mean) - `compar_rate'  in `i'
    }
    Allow me to suggest that you take some time to review chapters 11-13 of the Stata User's Guide PDF included in your Stata installation and accessible from Stata's Help menu. The objective in doing the reading is not so much to master Stata as to become familiar with a wide variety of important basic techniques, so that when the time comes that you need them, you might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

    Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it. These sections surfacee the things you need to know to work effectively.

    Comment


    • #17
      Originally posted by Farogat WIUT View Post
      Hi Andrew, I was able to access the virtual desktop from uni with Stata17.

      May I ask what is the function of "in `i' " in this loop?:
      As explained by William, this is discussed in

      Code:
      help in

      What it does is to select the observation number. The loop starts from 1 in increments of 1, so you have 1-2-3-4- ... -200. What I tell Stata to do is to store the first result in observation 1, the second in observation 2, and so on. These correspond to iterations of the loop.
      Last edited by Andrew Musau; 02 Feb 2022, 03:17.

      Comment


      • #18
        Yes, then my understanding of loop is correct.
        I added the line into the loop, but I keep receiveing an error message.
        Click image for larger version

Name:	r111.PNG
Views:	1
Size:	167.9 KB
ID:	1647971

        Comment


        • #19
          Make sure that the local is defined. If the local is empty, you will get the error. Compare:

          Code:
          sysuse auto, clear
          frame create results1
          frame results1{
              set obs 200
              gen results1=.
          }
          sum foreign
          forval i=1/2{
              frame results1: replace results1= r(mean)- `compar_rate' in `i'
          }
          frame results1: l in 1/2
          Res.:

          Code:
          . frame results1: replace results1= r(mean)- `compar_rate' in `i'
          in not found
          r(111);


          Code:
          sysuse auto, clear
          frame create results1
          frame results1{
              set obs 200
              gen results1=.
          }
          local compar_rate=0.5
          sum foreign
          forval i=1/2{
              frame results1: replace results1= r(mean)- `compar_rate' in `i'
          }
          frame results1: l in 1/2
          Res.:

          Code:
          . frame results1: l in 1/2
          
               +-----------+
               |  results1 |
               |-----------|
            1. | -.2027027 |
            2. | -.2027027 |
               +-----------+

          Comment


          • #20
            Addine to Andrew's response, I will assume the code you ran was taken from post #15 with the correction noted in post #16, thus
            Code:
            local compar_rate 0.898
            
            forval i=1/200{
            clear
            set obs 1477
            gen obs_id = runiformint(1, 1477)
            merge m:1 obs_id using Kaz.dta, keep(match) nogenerate
            estimates restore Uzb`i'
            predict yhat
            qui sum yhat
            frame results1: replace results1= r(mean) - `compar_rate'  in `i'
            }
            If that is the case, then it is almost certainly the case that your error message resulted from first selecting and running the single line that defined the local macro compar_rate, and then selecting the entire loop and running it. You can resolve this problem by running the local command and the loop at the same time.

            Consider the following example. In the do-file editor window, I have a two-line program that I run in its entirety.
            Code:
            . do "/Users/lisowskiw/Downloads/example.do"
            
            . local message Hello, world.
            
            . display "The message is `message'"
            The message is Hello, world.
            
            . 
            end of do-file
            
            .
            Now I run the same two lines by selecting the first line and running it, then selecting the second line and running it.
            Code:
            . do "/var/folders/xr/lm5ccr996k7dspxs35yqzyt80000gp/T//SD04017.000000"
            
            . local message Hello, world.
            
            . 
            end of do-file
            
            . do "/var/folders/xr/lm5ccr996k7dspxs35yqzyt80000gp/T//SD04017.000000"
            
            . display "The message is `message'"
            The message is 
            
            . 
            end of do-file
            
            .
            The important thing to keep in mind is that local macros vanish when the do-file within which they were created ends. If you look carefully at the results above, you'll see that when I selected a single line to run, it was copied into a temporary do-file and run, so even though both lines are in the same window in the do-file editor, they are run as separate do-files, and local macro defined in the first line vanishes at the end of that do-file, and is undefined when the second line is run.

            Comment


            • #21
              Couldn't have thought about that possibility. Thanks!

              Comment


              • #22
                Since it's the continuation of the topic above, I didn't create another post.
                Well, I am resampling the dataset and running regression each time. For comparison purposes, I have to run regressions with and without a certain variable (x). If I do the second regression in another loop with different resampling, then it will make no sense to compare. So, I am adding another regression into the same loop, so that two types of regressions are done for the same observations resampled. Now the question is, how and where do I have to set the limit for Stata17? Before all of the codes, I did:

                set maxvar 10000, permanently

                But still, I got error r(1000) regarding the limits. As far as I understood, the limit is now 5000, that's why I wanted to set to 10000. It seems there's a different issue here.
                Last edited by Farogat WIUT; 02 Feb 2022, 17:13.

                Comment


                • #23
                  I would suggest that you start a new thread as this is a different question. Also, present (copy and paste) the exact Stata output in full.

                  Comment

                  Working...
                  X