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
Hardware for Stata double-digit-core versionI think I will upgrade my Stata to 32-core or more. But I am wondering what hardware I have to buy.…
Arellano-Bond test AR(2)Dear Statalisters, I have one doubt about the result of my Arellano-Bond test for autocorrelation i…
Cumulative sum by order and idHi all, I am working on this dataset, in which I would like to test whether the cumulative sum of t…
Interpretation of K-fold cross-validation's resultsDear all, Hope you all are doing well. I have graphical results of K-fold cross-validation checks …
Problem with negative values in log-transformationNegative values are deleted in log-transforming. How can negative values be log-transformed without …
Subscribe to:
Post Comments (Atom)
0 Response to Loop computations across many .dta files and define new variable based on computation
Post a Comment