[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Extracting scalar from a vector

From   "John Pfaff" <>
To   <>
Subject   st: Extracting scalar from a vector
Date   Wed, 07 Oct 2009 12:07:51 -0400

Thanks to those who helped me with my question yesterday. One more quick question after that.

I'm trying to extract a scalar value from a vector and use it in a forval loop. The code I have is this:

foreach s in 6 8 17 21 {
  keep if state == `s'
  forval i = XXX (1) 16 { 

It's the XXX that is the problem. I have a vector x that takes on different values for each state s, and I want the forval loop to run from that value to 16. In other words, x == 14 when s  == 6, x == 10 when s == 8, and so on. But I have a lot of observations per state, so while x is constant for each state it is still a vector. How do I extract its scalar value to insert where the big XXX is in my code? This seems like it should be simple, but I've been thwarted for a while now.

Thanks so much!

All the best,

John Pfaff

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index