Dear all STATA users,
I am new to STATA and have run into some issues with a data task. I hope you can help me find a solution.
Data setup: I have about 1,000 separate .dta files containing daily data on a stock's price and volume (each .dta file represents a day of trading). The daily files contain observations to the nanosecond so it's not possible to append the files together.
Problem: I need to compute a simple mean and median for a specific time-period on each day, and I would like to generate a (column vector) numerical variable (= mean of each day) that I can use for regression analysis. I have created a foreach loop that goes into each file and makes the computation, but I have trouble generating the variable/storing/saving it so I can't use it for further analysis.
Code:
clear
set more off
program drop _all
cd "C:\Users\MadsA\Desktop\Information and Architecture of Financial Markets\Report\Daily_RICs"
local files : dir . files "*.dta"
** Create loop that generates variables for analysis
foreach file of local files {
use "`file'"
capture gen IAP = mean price if type == "Auction" & hours<16
capture gen Volume = volume if type == "Auction" & hours>9
}
When I run the code, STATA prompts "no; dataset in memory has changed since last saved"
Thanks in advance. I appreciate your help.
Related Posts with Loop computations across many .dta files and define new variable based on computation
Problem with Estpost and Esttab, exporting to LatexHello all, I am running some issues in exporting my tabulate result into Latex. my code is …
multiple regression - r(2000) error messageHi everyone, I am new here and quite new to Stata (student) so thank you upfront for your help. I …
EKC on STATAHello, I am comparing a linear, quadratic and cubic regression results of a Panel dataset. Those are…
How can I estimate a pseudo-gravity equationHello everyone I a little bit new with Stata and now I am using the pseudo-gravity equation from the…
Stata LoopsDear all, I have a long occupational dataset with several rows of observations for each person repr…
Subscribe to:
Post Comments (Atom)
0 Response to Loop computations across many .dta files and define new variable based on computation
Post a Comment