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
If and commandHello, Can you help me please with my following issue? I have a panel data set and I want to figure…
Max value changes because of different formatDear Statalist, This is my first time on this forum and untill now I have found a lot of answers fo…
What is the difference between xtreg ,mle versus reg ,(cluster id), can I use the results of one to confirm the results of the otherHi, My supervisor and staticien are asking me to run my panel regression with two methods, xtreg ,m…
Vlookup style function of variable from other datasetDear all, I come to you as I face a problem that sounds easy but I have stuck for good. I have two …
kmatch bandwidthI am running Stata 14.2 on Win 7E. I'm using propensity score matching on some observational data. I…
Subscribe to:
Post Comments (Atom)
0 Response to Loop computations across many .dta files and define new variable based on computation
Post a Comment