+ Reply to Thread
Results 1 to 2 of 2

Compute New Variable(column) with If Statements - Like in SPSS/Stata/Etc.

  1. #1
    Registered User
    Join Date
    01-10-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Compute New Variable(column) with If Statements - Like in SPSS/Stata/Etc.

    Hello,

    Does anyone know if I can compute a new variable in a new column using if statements - similar to that of statistical software?

    For instance, if I have individual data in each row: if baseball = 1 and youth = 1 then columnC = 1 else columnC = 0

    They way I managed to do it was not efficient for 40000 records in multiple data sets:


    Dim LR As Long
    LR = Range("S" & Rows.Count).End(xlUp).Row

    For rownum = 1 To LR

    If (Cells(rownum, Range("Baseball").Column) = 1) And Cells(rownum, Range("Youth").Column)= 1 Then
    Cells(rownum, Range("columnC").Column) = 1
    Else
    Cells(rownum, Range("columnC").Column) = 0
    End If


    Next rownum


    Thanks & Cheers!

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,952

    Re: Compute New Variable(column) with If Statements - Like in SPSS/Stata/Etc.

    Why can't you use a worksheet formula like: =AND(A1,B1)*1 with A1 & B1 are replaced by the baseball and youth columns?
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Loop on example on stata command
    By konradz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-21-2013, 08:46 AM
  2. [SOLVED] IF then with column vector and variable true statements
    By kelevra in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-08-2013, 02:19 PM
  3. Compute Average base on different column
    By ray_bt in forum Excel General
    Replies: 2
    Last Post: 05-23-2010, 12:23 PM
  4. Need to compute values in 2 column's
    By michael.woosley in forum Excel General
    Replies: 3
    Last Post: 07-24-2006, 12:35 AM
  5. using an address stored in a variable to compute the sum
    By dialerguy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2005, 04:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1