# Creating a data set

#### Monkeyface

##### New Member
I'm doing my econometrics term paper on the arbitrage pricing theory, and I need to import the historical prices of a 100 shares over the 2006-2010 period, and then divide those 100 shares into portfolios of 5 shares each. I am completely lost on how to do this...

Whenever I use the command stockquote to import prices for a stock, it overwrites the data of the previous stock...

Can anyone help me out with this issue?

Thank you very much!!

#### bukharin

##### RoboStataRaptor
-stockquote- is not an official Stata command. I assume you're talking about the user-written program from SSC; it's a good idea to clarify this when asking questions so that everyone's on the same page.

I haven't used -stockquote- but you probably need to do something like:
Code:
tempfile stocks
stockquote ...
save stocks'
stockquote ...
append using stocks'
save stocks', replace
stockquote ...
append using stocks'
save stocks', replace
...
If you need to run -stockquote- a large number of times (eg once per company) you could put some of the above in a loop, eg:
Code:
tempfile stocks
stockquote ... (company1)...
save stocks'
foreach company in company2 company3 ... {
stockquote ...
append using stocks'
save stocks', replace
}

#### Monkeyface

##### New Member
Thanks!

I have another question, when I try to find the return on a stock, for example XOM, I use this command:
gen RXOM=(f.XOM/XOM)-1

But stata gives back error r(111) time variable not set.

How do I solve this?

#### bukharin

##### RoboStataRaptor
It looks like you're trying to use time-series operators (in this case f.). You need to set the time variable (and, I suspect, the panel variable to indicate which observations belong to which companies) in order for these operators to work. See -help tsset-. You're probably after something like:
tsset companyvar timevar