Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

# Re: st: Generating a Variable indicating Change

 From Kelvin Mulungu To statalist@hsphsun2.harvard.edu Subject Re: st: Generating a Variable indicating Change Date Thu, 6 Jun 2013 19:46:21 +0300

```Thank you Rebecca. Yes, I have crop-level panel data and what I wanted
to do is the first example you have provided. Am really looking at the
change in land say allocated to crop A between this year (t) and
previous year (t-1). And the first example has worked. Thank you.

On Thu, Jun 6, 2013 at 6:54 PM, Rebecca Pope <rebecca.a.pope@gmail.com> wrote:
> Kelvin,
> Do you mean that you want the new variable to be the amount of the
> change or whether a change occurred? I've given an example of both.
>
> Let's say you have the following variables (for future reference, it
> is a good idea to provide some idea of the relevant variables &
> structure of your data):
>
> croptype - an ID variable for the type of crop
> year - the year of measurement
> acres - the number of acres of land devoted to crop(i) in year(t)
>
> I have assumed that you have crop-level panel data based on your
> question. Please correct me if I'm wrong.
>
> *** begin example ***
>  // use by and Stata's subscripts to calculate amount of change
> bysort croptype (year): gen amtchng = acres-acres[_n-1]
>
>  // use Stata's lag operator and logical test to create indicator
>  // for whether or not change occurred
> bysort croptype (year): gen anychng = (acres-acres[_n-1] != 0) if _n!=1
> *** end example ***
>
> The second -bysort- isn't strictly necessary if you run both commands.
> You can just use -by- the second time.
>
> Regards,
> Rebecca
>
> On Thu, Jun 6, 2013 at 7:53 AM, Kelvin Mulungu
> <kelvin.statalist@gmail.com> wrote:
>> Hi All,
>>
>> I want to generate a variable that is supposed to show the change in
>> land planted to a certain crop. Is there a single command for doing
>> this or I just lag the variable first, then get the difference?
>>
>> Thanks.
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```

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