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
To both experienced Stata programmers, and Stata users: How do you prefer to have the command, as a post estimation or as a prefix?Good afternoon, I have written a command to estimate robust variance post Seemingly Unrelated Regre…
can i use mi chained logistic and how to weight respondentsi have combined survey data sets from 32 countries and have about 90k respondents, the number of res…
Direction of bias?Dear all, I am trying to determine directions of biased (upward or downward) estimates in my study …
Aidsills with market fixed effectsDear Statalisters, I am using Stata ver 14, and the built in command aidsills written by Lecocq and…
Background Color Twoway ChartDear all, I am trying to change the background colour of a twoway chart but it is not working, I ha…
Subscribe to:
Post Comments (Atom)
0 Response to Loop computations across many .dta files and define new variable based on computation
Post a Comment