Announcement

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

  • Postfile results not stored in new stata file

    Hello all,

    I am very new to Stata and I am having some trouble using the Postfile function. I am following a do file that my lecturer has given me and when he runs the following code, a new stata file called 'resultsbeta' is generated for him. The results are shown in stata for me (as they are for the lecturer), but they are not stored in a new file.
    Code:
    tempname memhold
    postfile `memhold' beta_values str32 varname using "resultsbeta", replace
    
    // Loop over each variable in the list
    foreach var in `variable_list' {
    
        // Calculate the covariance between the current variable and return_ftse100priceindex
        corr `var' return_ftse100priceindex, cov
        scalar beta_values = r(C)[1, 2] / var_ftse
        
        post `memhold' (beta_values) (`"`var'"')
    
    }
    postclose `memhold'
    Below is an attached an image of what the new file should look like (low quality unfortunately).
    Click image for larger version

Name:	Screenshot 2024-03-27 at 17.30.22.png
Views:	1
Size:	330.2 KB
ID:	1748035


    Again, I am very new to stata so I apologise if I am overlooking something or if this is a very easy fix.
    Thanks

  • #2
    How are you trying to find/access the new file? Do not try to reach it via `memhold': that is no longer usable after -postclose-. You must, thereafter, refer to the file by its name: resultsbeta. -dir resultsbeta.dta- should show you it exists, and -use resultsbeta, clear- should bring it into memory. If these are not working, please repost showing the exact code that you are using to try to access the new file.

    Comment


    • #3
      Hi Clyde,
      I was trying to find the file by looking at my folder where the file should be stored and it wasn't appearing. Similarly, I used:
      Code:
      use "/Users/bilaalaslam/Desktop/CASS/Year 3/Term 2/Applied Research Project/IARP data/resultsbeta.dta"
      and it said that it was not found. However, I used your -dir resultsbeta.dta- and -use resultsbeta, clear- commands and then used the save command and it worked. Thank you very much!

      Comment


      • #4
        What that means is that when you ran the code, the current working directory was not "/Users/bilaalaslam/Desktop/CASS/Year 3/Term 2/Applied Research Project/IARP data." Any time Stata saves a file, unless you give it a full path in the -save- command (-or the -using- part of the -tempfile- command), the file is saved in the current working directory. Moreover, any -use- command, again, unless you specify a full path, will be sought in current working directory.

        So your next task is to learn what the current working directory actually is. The -pwd- command will tell you that. (On Windows you can also use -cd- for this.) You can find the file there going forward.

        Comment

        Working...
        X