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.